简体   繁体   中英

Insert data into one table and update another

I have 2 different tables project and 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 .

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%' . It should be AND cost like '%$money%'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM