下面的代码运行没有错误,尽管它没有向我的数据库中插入任何内容:
<?php
$con=mysqli_connect("localhost","root","","teachme");
//check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//add details in database
if (isset($_POST['user']) and isset($_POST['pass']) and isset($_POST['division'])) {
$user = mysql_real_escape_string($_POST['user']);
$pass = mysql_real_escape_string($_POST['pass']);
$division = mysql_real_escape_string($_POST['division']);
mysqli_query($con,"INSERT INTO users (username, password, division, id)
VALUES ($user, $pass, $division)");
echo 'Succesfully added entries onto the database.. ';
echo $user;
echo $pass;
echo $division;
echo '<a href="../">Return to homepage</a>';
}
else {
echo "An error occured, try again!";
}
?>
所有变量都正确传输,这就是我使用上面的 echo 语句的原因。我是新手,我知道这一定是一个非常愚蠢的问题。