[英]Mysql Insert Statement from PHP
I am trying to run PHP could which inserts a value into a MySQL table. 我试图运行PHP可以将值插入MySQL表的PHP。
My db connection is working ok. 我的数据库连接正常。
I have the code in a function: 我在函数中有代码:
function InsertRighmoveID($RightmoveID)
{
# Connection already created in main program
#Define the query to insert righmove ID already in Database
#VALUES ('" . substr($name, 23, 31) . "')";
echo "In InsertRighmoveID() function </br>";
$query_enter_rightmove_ID =
"INSERT INTO tblRightMoveIDs (rightmoveID)
VALUES ('" . $RightmoveID . "');";
#Echo the query to check it
echo $query_enter_rightmove_ID . "</br>";
#Execute the query
$query_enter_rightmove_ID = mysql_query($query_enter_rightmove_ID);
echo "Leaving InsertRighmoveID() function </br>";
#Execute the query
$query_enter_rightmove_ID = mysql_query($query_enter_rightmove_ID);
#Check to see if the query worked
if (!$query_enter_rightmove_ID)
{
die("Database query failed:" . mysql_error());
}
echo "Leaving InsertRighmoveID() function </br>";
}
when I run the code in a webpage, get it to print the query to screen this is the message: 当我在网页中运行代码时,获取它以打印查询以显示以下消息:
INSERT INTO tblRightMoveIDs (rightmoveID) VALUES ('44047607')
Database query failed: 数据库查询失败:
You have an error in your SQL syntax;
您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1
检查与您的MySQL服务器版本相对应的手册,以在第1行的'1'附近使用正确的语法
44047607 is the value passed to the function. 44047607是传递给函数的值。
If I run the: 如果我运行:
INSERT INTO tblRightMoveIDs (rightmoveID) VALUES ('44047607');
Outside the program it works. 在程序之外,它可以工作。
Remove the semicolon ;
删除分号
;
from here 从这里
"INSERT INTO tblRightMoveIDs (rightmoveID)
VALUES ('" . $RightmoveID . "');";
-------^
There is error here in the starred parts: 已加星标的部分存在错误:
**$query_enter_rightmove_ID** = mysql_query($query_enter_rightmove_ID);
echo "Leaving InsertRighmoveID() function </br>";
#Execute the query
$query_enter_rightmove_ID = mysql_query(**$query_enter_rightmove_ID**);
You are executing mysql_query first time with a proper query and it puts the result into $query_enter_rightmove_ID variable. 您是第一次使用适当的查询执行mysql_query,并将结果放入$ query_enter_rightmove_ID变量中。 Second time, you are using the result of first query as the parameter to mysql_query which is wrong
第二次,您将第一次查询的结果用作mysql_query的参数,这是错误的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.