Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mysql PDO更新,其中id=?_Php_Mysql_Insert - Fatal编程技术网

Php mysql PDO更新,其中id=?

Php mysql PDO更新,其中id=?,php,mysql,insert,Php,Mysql,Insert,有人能告诉我为什么这不起作用吗 $db = new PDO("mysql:host=localhost;dbname=classifieds2", 'root', ''); // 1. set database with this instead of conect - or change conect to this $query="UPDATE `listings` SET (`date`,`firstname`,`lastname`,`title`,`info`,`location`,`

有人能告诉我为什么这不起作用吗

$db = new PDO("mysql:host=localhost;dbname=classifieds2", 'root', ''); // 1. set database with this instead of conect - or change conect to this

$query="UPDATE `listings` SET (`date`,`firstname`,`lastname`,`title`,`info`,`location`,`phone`,`postcode`,`town`,`city`,`image`,`image2`,`image3`,`image4`,`image5`,`price`,`catagory`,`cond`,`delivery`,`username`,`email`,`youtubevideo`,`paypal`,`facebook`,`twitter`,`feedbackscore`) WHERE listID=? VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";


$stat=$db->prepare($query);$stat=$db->prepare($query);


$stat->execute(array("$now","$firstname","$lastname","$sellingtitle","$sellinginfo","$town","$phone1","$postcode","$town","$city","$i0url","$i1url","$i2url","$i3url","$i4url","$price","$catagory","$cond","$delivery","$sellername","$email","$youtubeurl","$paypal","$facebook","$twitter","feedbackscore","$listID"));
我正在尝试使用insert创建一个表并为其创建一个唯一id,然后我希望在另一个页面上更新该表,但选择具有唯一id的表

但由于某些原因,我得到的只是第一次插入工作,但更新不会。。有人能帮忙吗

非常感谢

创建具有唯一ID的表

$listID=rand(10,100);

$db = new PDO("mysql:host=localhost;dbname=classifieds2", 'root', ''); // 1. set database with this instead of conect - or change conect to this

$query="INSERT INTO `listings` (`username`,`listID`) VALUES (?,?)";

$stat=$db->prepare($query);$stat=$db->prepare($query);

$stat->execute(array("$accountname","$listID"));
然后使用以下代码更新该表,但该代码不起作用

$db = new PDO("mysql:host=localhost;dbname=classifieds2", 'root', ''); // 1. set database with this instead of conect - or change conect to this

$query="UPDATE `listings` SET (`date`,`firstname`,`lastname`,`title`,`info`,`location`,`phone`,`postcode`,`town`,`city`,`image`,`image2`,`image3`,`image4`,`image5`,`price`,`catagory`,`cond`,`delivery`,`username`,`email`,`youtubevideo`,`paypal`,`facebook`,`twitter`,`feedbackscore`) WHERE listID=? VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";


$stat=$db->prepare($query);$stat=$db->prepare($query);


$stat->execute(array("$now","$firstname","$lastname","$sellingtitle","$sellinginfo","$town","$phone1","$postcode","$town","$city","$i0url","$i1url","$i2url","$i3url","$i4url","$price","$catagory","$cond","$delivery","$sellername","$email","$youtubeurl","$paypal","$facebook","$twitter","feedbackscore","$listID"));

listid
通过POST发送到更新的接收页面,并从第一次查询将唯一ID插入表中,但更新不起作用。有人知道为什么吗?

所有这些变量都用双引号括起来,这是怎么回事?这是不必要的。将PDO设置为抛出异常,它将告诉您失败的原因。请记住,每个
都必须在
execute
的数组的同一位置具有适当的对应值。您的
$listID
应该位于该数组的前面,而不是末尾。还可以将它们简化为一个:
$stat=$db->prepare($query)$stat=$db->prepare($query)不是更新语法
更新表名集fieldname=?,field2=?where key=?
我不确定值是否可以在sql update语句中的where之后。任何人
Update listings set column1=?, 
column2=? Where column3=?