添加信息Mysql

时间:2015-10-28 11:26:59

标签: php html

这说我第15行有错误。

我希望添加信息,然后将其显示在表格中。 enter image description here

解析错误:语法错误,意外';'在第15行的N:\ ftp \ compc \ ac12mm \ untitled文件夹\ addContact.php

3 个答案:

答案 0 :(得分:0)

以这种方式更改您的查询:

INSERT INTO TABLE_NAME (id,name, ...) VALUES (0,'name', ..) ;

答案 1 :(得分:0)

您忘记关闭$db->prepare功能。

替换它(第15行):

$dbQuery = $db->prepare("insert into stock values (
     null, :game, :console, :age, :genre,:price, :status, :stock, :purchased,
     :low, :date, :picture,)";

有了这个:

$dbQuery = $db->prepare("insert into stock values (
         null, :game, :console, :age, :genre,:price, :status, :stock, :purchased,
         :low, :date, :picture)");

同时

替换它(第16行):

$dbParams = array('game'=> $newstockgame, 'console'=> $newstockconsole,
'age'=> $newstockage, 'genre'=> $newstockgenre, 'status'=> $newstockstatus, 
'purchased'=> $newstocklow, 'date'=> $newstockdate, 'picture'=> $newstockpicture);

有了这个:

$dbParams = array('game'=> $newstockgame, 'console'=> $newstockconsole, 
'age'=> $newstockage, 'genre'=> $newstockgenre, 'price'=> $newstockprice, 
'status'=> $newstockstatus, 'stock'=>$newstockstock, 'purchased'=> $newstockpurchased, 
'low'=>$newstocklow, 'date'=> $newstockdate, 'picture'=> $newstockpicture);

答案 2 :(得分:0)

您的代码中存在语义错误:

$dbQuery = $db->prepare("insert into stock values (null, :game, :console,
:age, :genre, :price, :status, :purchased, :low, :date, :picture,)";

看看最后,你需要修复你的线路,像这样的事情会更好地工作:

$dbQuery = $db->prepare("insert into stock values (null, :game, :console,
:age, :genre, :price, :status, :purchased, :low, :date, :picture)");

删除","之后"图片"并添加")"关闭你的语句会产生一个有效的php行。

编辑:您还忘记为":price",":stock"添加参数和":低"在第16行,如果你没有设置这些变量,你的查询可能会失败。