PHP代码
<?php
$imageId = $_GET ["a"];
$likerId = $_GET ["b"];
// connection to the database
$dbhandle = mysql_connect ( "localhost", "root", "" ) or die ( "Unable to connect to MySQL" );
// select a database to work with
$selected = mysql_select_db ( "taxogram", $dbhandle ) or die ( "Could not select login" );
// execute the SQL query and return records
$result = mysql_query ( "INSERT INTO liker ( imageId , likerId ) VALUES ( '$imageId' , '$likerId' ) " );
echo mysql_error () . "<br>";
if ($result == 1) {
echo "sukses";
} else {
echo "gagal";
}
?>
错误
您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在第1行的'like(imageId,likerId)VALUES('1','2')附近使用正确的语法 gagal
答案 0 :(得分:1)
&#34;像&#34;是reserved keyword。
$result = mysql_query ( "INSERT INTO `like` ( imageId , likerId ) VALUES ( '$imageId' , '$likerId' ) " );
另请注意mysql_ functions are deprecated。请改用Mysqli或PDO。