我正在尝试将一些 post 变量插入数据库,但似乎无法使其正常工作。这是我目前的代码。
include('db_connect.php'); // = $connection
$name = $_POST['name'];
$email = $_POST['email'];
$result = mysqli_query($connection,"SELECT * FROM users WHERE email='$email'");
$row = mysqli_num_rows($result);
if($row==0)
{
echo("email was not found");
mysqli_query($connection,"INSERT INTO users (name, email, comfirmed) VALUES ('".$name."', '".$email."', 0)");
}
else
{
echo("email was found");
}
我已经尝试了几种插件的变体,但无法让它工作。如果我用静态值替换变量,那么它可以正常工作并且我的数据库会更新。我也意识到此时存在安全问题,但我想专注于让插入工作然后返回并修复这些问题。