我最近搬到了另一个地方,我遇到了一个问题。当我以网站的形式输入数据时,数据库不会更新。然而,当我的托管服务的运营商站在他们这边做的时候,这个表单似乎对他们有用。为什么会这样?
下面是php中的数据库调用
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
$name = $_POST['name1'];
$surname = $_POST['surname1'];
$email = $_POST['email1'];
$email = filter_var($email, FILTER_SANITIZE_EMAIL); // Sanitizing E-mail.
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
define('DB_NAME', 'name');
define('DB_USER', 'user');
define('DB_PASSWORD', 'password');
define('DB_HOST','localhost');
$conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$name = mysqli_real_escape_string($conn, $name);
$surname = mysqli_real_escape_string($conn,$surname);
$email = mysqli_real_escape_string($conn,strtolower($email));
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO interested (Name, Surname, Email) VALUES ('$name', '$surname', '$email')";
if ($conn->query($sql) === TRUE) {
echo "Thank you!";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
} else {
echo "<span>* invalid email *" + $email +"</span>";
}
?>
1条答案
按热度按时间1tuwyuhd1#
我忘了提到,你也必须激活错误报告的mysql级别了。e、 g.设置
$mysqliDriver->report_mode
,如下所示。因此,在更改db凭证之后,按原样测试此代码。如果有效,那么问题就存在于代码中。如果不是,那它就在别的地方。