<?php
include("../scripts/createconnect.php");
if(isset($_POST['submitted'])) {
$username = mysql_real_escape_string ($_POST['username']);
$password = mysql_real_escape_string ($_POST['password']);
$sqlinsert = "INSERT INTO Testing (User_Id, username, password)
VALUES (NULL,'$username', '$password');";
if (!mysqli_query($dbcon, $sqlinsert)) {
die('error inserting into database');
} // end of nested if statement
$newrecord ="Congratulations!";
}
?>我通过数据库输入了一个工作表单。我正在学习MySql注入预防。
我一开始尝试使用mysql_real_escape_string方法,但似乎遇到了格式错误。
我已确认我的数据库已连接。当我将mysql_real_escape_string添加到表单输入时,我现在遇到了一个错误。
我的远程文件"createconnect.php“通过mysqli_connect成功连接。
我添加了教程中详细介绍的ysql_real_escape_string,现在无法向MYSQL数据库输入数据。谁能告诉我我错过了什么?
发布于 2012-10-17 18:28:15
你不能用这种方式写代码。mysql函数不能在mysqli中使用,如果你想使用mysqli来运行php查询。请查看此链接:http://scriptforyou.com/mysql-easily-insert-and-update-records/。这是使用mysqli的最佳教程。
也要避免使用mysql_real_escape_string。编码快乐!!
发布于 2012-10-17 18:35:38
对于mysqli,有一个类似的函数,称为mysqli_real_escape_string
试一试
$link = new mysqli("localhost", "my_user", "my_password", "dbaname");
$username = mysqli_real_escape_string ($link,$_POST['username']);
$password = mysqli_real_escape_string ($link,$_POST['password']);https://stackoverflow.com/questions/12863824
复制相似问题