我有两个PHP文件,Database_conn和findOutMore
database_conn中的PHP:
<?php
$webserver = 'localhost';
$password = 'xxxx';
$username = 'xxxx';
$database = 'xxxx';
$conn = mysqli_connect( $webserver, $username, $password, $database);
if (!$conn) {
die("Connection failed: ".mysqli_connect_error());
}
?>
和findOutMore中的PHP
<?php
include 'database_conn.php';
$forename = $_REQUEST['forename'];
$surname = $_REQUEST['surname'];
$email = $_REQUEST['email'];
$landline = $_REQUEST['landLineTelNo'];
$mobile = $_REQUEST['MobileTelNo'];
$address = $_REQUEST['postalAddress'];
$method = $_REQUEST ['sendMethod'];
echo"<h3> These are your details </h3>";
echo"Name: ";
echo $forename;
echo " ";
echo $surname;
echo "<br>";
echo "Email: ";
echo $email;
echo "<br>";
echo "Landline: ";
echo $landline;
echo"<br>";
echo "Mobile: ";
echo $mobile;
echo "<br>";
echo "Address: ";
echo $address;
echo "<br>";
echo"Contact Method: ";
echo $method;
$query="INSERT INTO Database_Table
(forename, surname, postalAddress, landLineTelNo, MobileTelNo, email, sendMethod)
values (NULL, '$forename','$surname','$address','$landline','$mobile','$email','$method')";
if (mysqli_query($conn, $query)) {
echo "New record created successfully";
}
mysqli_close($conn);
?>
我实际上并没有收到任何错误,并且回声正常工作(返回用户输入的值。)但数据实际上从未输入数据库。
我认为可能是在值的开头处使用NULL,但我不确定如何更改它,因为它应该是主键,即ID条目。
答案 0 :(得分:2)
您需要实际运行查询;)
http://php.net/manual/en/mysqli.query.php
mysqli_query($conn, $query);
我想指出,你的剧本非常不安全。您应该查看使用预准备语句,并可能切换到PDO: