Ryl*_*ron 2 php mysql ajax jquery jquery-jtable
我正在使用这个例子: www.jtable.org
我已经下载了jTable PHP版本.然后我编辑了脚本.jTable简单版本正在运行,但我编辑的版本不是.
我可以创建一个列表,但我不能添加一行; 这段代码导致了问题.但是,PHP不会显示任何错误消息.
else if($_GET["action"] == "create")
{
//Insert record into database
$result = mysql_query("INSERT INTO veriler(bolge, sehir, firma, adres, tel, web) VALUES('" . $_POST["bolge"] . "', '" . $_POST["sehir"] . "', '" . $_POST["firma"] . "', '" . $_POST["adres"] . "', '" . $_POST["tel"] . "', '" . $_POST["web"] . "'");
//Get last inserted record (to return to jTable)
$result = mysql_query("SELECT * FROM veriler WHERE id = LAST_INSERT_ID();");
$row = mysql_fetch_array($result);
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Record'] = $row;
print json_encode($jTableResult);
}
Run Code Online (Sandbox Code Playgroud)
问题是什么?
rat*_*oss 10
在这一行中,存在一个问题:
$result = mysql_query("INSERT INTO veriler(bolge, sehir, firma, adres, tel, web) VALUES('" . $_POST["bolge"] . "', '" . $_POST["sehir"] . "', '" . $_POST["firma"] . "', '" . $_POST["adres"] . "', '" . $_POST["tel"] . "', '" . $_POST["web"] . "'");
Run Code Online (Sandbox Code Playgroud)
INSERT查询的格式为:
INSERT INTO table (column1, column2, etc) VALUES (value1, value2, etc);
Run Code Online (Sandbox Code Playgroud)
您错过了VALUES部分的右括号.
要改进代码,您可以执行以下操作:
$result = mysql_query("YOUR QUERY") or die('ERROR: '.mysql_error());
Run Code Online (Sandbox Code Playgroud)
请阅读SQL注入.