查看: 2061|回复: 8
|
php insert into select的问题
[复制链接]
|
|
我想要把部分records从一个table insert去另一个,不过我的orderID,Address,town,state,total,postcode是一样的。- <?php
- session_start();
- include ("connect.php");
- $OrderID=$_POST['OrderID'];
- $Total=$_POST['Total'];
- $Address=$_POST['address'];
- $Town=$_POST['town'];
- $State=$_POST['state'];
- $Postcode=$_POST['postcode'];
- $sql="INSERT INTO orderrecord(OrderID, ProductID,ProductName,UnitPrice,Quantity,TotalPrice,Total,Address,Town,State,Postalcode) Values ('$OrderID',(SELECT cart.ProductID,cart.ProductName,cart.UnitPrice,cart.Quantity,cart.TotalPrice from cart),'$Total','$Address','$Town','$State','$Postcode')";
- $result = $db->query($sql);
-
-
- if(! $result )
- {
- die('<script type="text/javascript">alert("Unsuccessful payment")</script>');
- echo mysql_error();
-
-
- }
- else{
- echo '<script type="text/javascript">alert("Payment Successfully")</script>';
- echo "<script language='javascript'>window.location='login.php'</script>";
- }
- ?>
复制代码 一直不能成功,是哪里出了问题吗?
|
|
|
|
|
|
|
|
发表于 14-9-2012 01:24 AM
|
显示全部楼层
Can try the following:
$sql="INSERT INTO orderrecord(OrderID, ProductID,ProductName,UnitPrice,Quantity,TotalPrice,Total,Address,Town,State,Postalcode)
(SELECT '$OrderID', cart.ProductID,cart.ProductName,cart.UnitPrice,cart.Quantity,cart.TotalPrice,
'$Total','$Address','$Town','$State','$Postcode' from cart)"; |
|
|
|
|
|
|
|
发表于 14-9-2012 03:33 AM
|
显示全部楼层
用一些工具.. 做 query testing..
如 SQLyog.. |
|
|
|
|
|
|
|

楼主 |
发表于 14-9-2012 07:48 AM
|
显示全部楼层
php+.net 发表于 14-9-2012 01:24 AM 
Can try the following:
$sql="INSERT INTO orderrecord(OrderID, ProductID,ProductName,UnitPrice,Qua ...
还是不可以啊。。。我的cart table里有很多records,不只一个。是不是要用loop?
|
|
|
|
|
|
|
|
发表于 14-9-2012 12:25 PM
|
显示全部楼层
h@@ 发表于 14-9-2012 07:48 AM 
还是不可以啊。。。我的cart table里有很多records,不只一个。是不是要用loop?
No need to use loop.
Any error message?
Try to display/show the exact value of $sql and then run it in your phpMyAdmin or any other database tool and see what is the error.
|
|
|
|
|
|
|
|

楼主 |
发表于 14-9-2012 12:42 PM
|
显示全部楼层
jasonmun 发表于 14-9-2012 03:33 AM 
用一些工具.. 做 query testing..
如 SQLyog..
我的sql应该对了。。只是不懂为什么在php insert 不了
|
|
|
|
|
|
|
|

楼主 |
发表于 14-9-2012 12:46 PM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 14-9-2012 12:50 PM
|
显示全部楼层
php+.net 发表于 14-9-2012 12:25 PM 
No need to use loop.
Any error message?
现在可以了。。在cart table还有一个column我忘了写。。谢谢啊
|
|
|
|
|
|
|
|
发表于 22-10-2012 11:24 PM
|
显示全部楼层
h@@ 发表于 14-9-2012 12:46 PM 
没有error message。submit了就只有unsuccessful payment罢了
请问你的unit price是从database抓是吗?
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|