[英]Insert data into one table and update another
I have 2 different tables project
and payments
. 我有2个不同的表project
和payments
。 When I insert a payment I want the value of flag
from the project
table to be changed to paid
if the $money inserted
are exactly the same as the value of cost
( cost
is another cell from the project
table) and the $order = proj_name
. 当我插入付款时,如果$money inserted
的$money inserted
与cost
的值( cost
是project
表中的另一个单元格)和$order = proj_name
完全相同,我希望将project
表中的flag
值更改为已paid
。
Here comes the code! 这是代码!
<?php
include("connect.php");
// define variables
$name = $_POST['name'];
$order = $_POST['order'];
$money = $_POST['money'];
$date = $_POST['date'];
$sql="INSERT INTO payments VALUES
('','$name','$order','$money','$date')";
$s="UPDATE project SET flag='payed' WHERE proj_name='$order' AND cost like '%money%'";
mysql_query($s);
echo '<center>' ."Payment stored successfully". '</center>';
echo '<center>'."<a href='payments_edit.php'>View Changes</a>".'</center>';
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close();?>
If you want any more info on anything let me know :) 如果您想要任何更多信息,请告诉我:)
You are missing $
in AND cost like '%money%'
. 你错过了$
in AND cost like '%money%'
。 It should be AND cost like '%$money%'
这应该是AND cost like '%$money%'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.