-2

I'm trying to update two tables with one query with same value but different IDs. I have been looking for solution but all I have found doesn't work for me here is the code:

$Image = $_SESSION["ImageName"];
$ImageID = $_POST['ImageID'];
$GalleryID = $_POST['GalleryID'];

$updateSQL = "UPDATE slideimage, gallery
              SET slideimage.ImageName='".$Image."', gallery.GalleryPoster='".$Image."'
              WHERE slideimage.ImageID='".$ImageID."'
              AND gallery.GalleryID='".$GalleryID."'
              ";
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • Have you tried https://stackoverflow.com/questions/15037883/mysql-update-syntax-with-multiple-tables-using-where-clause – Netham Nov 10 '17 at 12:23
  • 2
    Now would be a really good time to familiarise yourself with bound queries – Strawberry Nov 10 '17 at 12:23
  • Possible duplicate of [MySQL UPDATE syntax with multiple tables using WHERE clause](https://stackoverflow.com/questions/15037883/mysql-update-syntax-with-multiple-tables-using-where-clause) – Brian Tompsett - 汤莱恩 Nov 10 '17 at 15:40

1 Answers1

0

I would handle this in one of two ways depending on your setup.

  1. Have two separate updates, i.e. update one table, then update the other.
  2. Create a stored proc that you can pass the parameters to that updates the two tables.

Both of these solutions come directly from the database point of view. Please note I'm a MSSQL guy rather than MYSQL, but good practice on a database is good practice on a database.

May not directly be the answer you are looking for, but I hope it puts you on a good track.

Matthew Baker
  • 2,637
  • 4
  • 24
  • 49