在php中插入数据库时出错
我试图在我的php程序中向数据库插入一些值,但是我得到了错误在php中插入数据库时出错,php,Php,我试图在我的php程序中向数据库插入一些值,但是我得到了错误 Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\php\books.php on line 9 mysql\u查询 mysql_query("insert into books values('$_GET["title"]','$_GET["author"]','$_GET["edition
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\php\books.php on line 9
mysql\u查询
mysql_query("insert into books values('$_GET["title"]','$_GET["author"]','$_GET["edition"]','$_GET["publish"]','$_GET["isbn"]',)") or die(mysql_error());
在变量中获取值,如
$title = $_GET["title"];
$author = $_GET["author"];
然后像这样使用查询
mysql_query("insert into books values('$title','$author','$edition','$publish','$isbn',)") or die(mysql_error());
您正在使用嵌套双引号
mysql_query("insert into books values('{$_GET["title"]}','{$_GET["author"]}','{$_GET["edition"]}','{$_GET["publish"]}','{$_GET["isbn"]}',)") or die(mysql_error());
或
好的查询是:
mysql_query("insert into books values('" . $_GET["title"] . "','" . $_GET["author"] . "','" . $_GET["edition"] . "','" . $_GET["publish"] . "','" . $_GET["isbn"] . "')") or die(mysql_error());
在查询的末尾有非转义引号,但也有一个与此无关的逗号。
也许你应该先学习PHP及其语法。这是PHP错误,不是SQL错误。您的PHP中存在语法错误。特别是第9行。变量前可能缺少分号或dollarsign。我看到单引号和双引号。另外,请查看SQL注入。另外,请查看
mysql_query("insert into books values('" . $_GET["title"] . "','" . $_GET["author"] . "','" . $_GET["edition"] . "','" . $_GET["publish"] . "','" . $_GET["isbn"] . "')") or die(mysql_error());