0
任何人都可以告诉我为什么下面的代码给了我一个错误页面500.还有,怎么样,我可以纠正它。PHP MySql插入给服务器错误500
mysql_connect("xxx", "xxx", "xxx") or die(mysql_error());
mysql_select_db("xxx") or die(mysql_error());
$sql = "INSERT INTO oc2_ads (id_user, id_category)
VALUES ('$id_user', '$id_category')";
mysql_query($sql);
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
谢谢
你在使用什么服务器? – Oliver
请[停止使用'mysql_ *'函数](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。 [这些扩展](http://php.net/manual/en/migration70.removed-exts-sapis.php)已在PHP 7中删除。了解[编写](http://en.wikipedia.org/ wiki/Prepared_statement)语句[PDO](http://php.net/manual/en/pdo.prepared-statements.php)和[MySQLi](http://php.net/manual/en/mysqli.quickstart .prepared-statements.php)并考虑使用PDO,[这真的很简单](http://jayblanchard.net/demystifying_php_pdo.html)。 –
[您的脚本存在SQL注入攻击的风险。](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) –