运行多个查询一次

时间:2013-06-05 19:21:13

标签: php mysql insert sql-update multi-query

确定!我有一个脚本是现场拍卖的一部分,我的代码并非全部正常工作,而且我已经走到了尽头!下面的代码是我尝试过的两种方法,没有运气:

  <? if(isset($_GET['golive'])) { 

  $id = $_POST['id'];
  $totalamount = $_POST['amount'];
  $ordernumber = $_POST['ordernumber'];

  mysql_connect("localhost","DBusername","DBpassword") or  die(mysql_error()); 
  mysql_select_db("DBname") or die(mysql_error(header('Location: live_auction.php?ordermun=error'))); 

  mysql_query("INSERT INTO auction_bundle 
   (`purchaser_id`,`amount`,`order_number`,`date`) VALUES (".$id.",".$totalamount.",".$ordernumber.",NOW())
  UPDATE auction_products SET order_number=".$ordernumber." WHERE on_now=1;              
  UPDATE auction_products SET sold=1 WHERE on_now=1;
  UPDATE auction_products SET on_now=3 WHERE on_now=1"); 
  header('Location: live_auction.php?ordermun='.$ordernumber.'');

  } 
  ?>

我也试过

  <? if(isset($_GET['golive'])) { 

  $id = $_POST['id'];
  $totalamount = $_POST['amount'];
  $ordernumber = $_POST['ordernumber'];

  mysql_connect("localhost","DBusername","DBpassword") or  die(mysql_error()); 
  mysql_select_db("DBname") or die(mysql_error(header('Location: live_auction.php?ordermun=error'))); 

  mysql_query("INSERT INTO auction_bundle 
   (`purchaser_id`,`amount`,`order_number`,`date`) VALUES (".$id.",".$totalamount.",".$ordernumber.",NOW()");

  mysql_query("UPDATE auction_products SET order_number=".$ordernumber." WHERE on_now=1");              
  mysql_query("UPDATE auction_products SET sold=1 WHERE on_now=1");
  mysql_query("UPDATE auction_products SET on_now=3 WHERE on_now=1"); 
  header('Location: live_auction.php?ordermun='.$ordernumber.'');

  } 
  ?>

第二个能够更改auction_products表但仍然不会INSERT和其他查询。我错过了什么我需要在点击golive按钮时发生所有这四个。

1 个答案:

答案 0 :(得分:0)

您的插入查询无效,因为您最后忘了a)。

mysql_query("INSERT INTO auction_bundle 
   (`purchaser_id`,`amount`,`order_number`,`date`) VALUES (".$id.",".$totalamount.",".$ordernumber.",NOW()");

应该是:

mysql_query("INSERT INTO auction_bundle 
   (`purchaser_id`,`amount`,`order_number`,`date`) VALUES (".$id.",".$totalamount.",".$ordernumber.",NOW())");