这是我昨天问过的问题的扩展,但我无法找到解决问题的方法。这是我当前的代码,它似乎打破了$ result:
$host = 'localhost';
$user = 'dbuser';
$dbpass = 'password';
$dbname = 'users';
$cxn = mysqli_connect($host,$user,$dbpass,$dbname) or die("Could not connect to server.");
$email = $_POST['email'];
$username = $_POST['username'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$safe_email = mysqli_real_escape_string($cxn,$email);
$safe_username = mysqli_real_escape_string($cxn,$username);
$safe_first = mysqli_real_escape_string($cxn,$first_name);
$safe_last = mysqli_real_escape_string($cxn,$last_name);
$query = "insert into `user_data` (`email`, `username`, `first_name`, `last_name`) values ('$safe_email', '$safe_username', '$safe_first', '$safe_last')";
$result = mysqli_query($cxn,$query) or die('Can\'t complete query.');
echo "Congratulations!";
我已经检查了我网站上的错误报告,并且没有显示提交表单时创建的任何错误。我给了'dbuser'表的以下特权:INSERT,SELECT,UPDATE,DELETE和CREATE TEMPORARY TABLES。我还没有改变数据库本身的任何主要设置。