Jump to content

[SOLVED] update not updating


java12

Recommended Posts

I'm trying to update a race_id field in table 2 with an id field in table1 when name, venue, date and time fields match in table1 and table2.

 

The $date and $time2 are found after exploding the date field in table1, which seems to work correctly, so that "2007-05-17 19:15:00" becomes $date = 2007- 05-17 and $time2 = 19:15

 

But something is wrong with the update query as nothing is getting updated in the race_id field in table2 and I can't see why...

 

<?php
$res = mysql_query("SELECT date FROM table1");
while ($row = mysql_fetch_array($res))   {
list($date, $time) = explode(" ",$row[0]);
$time2 = substr($time,0,5);
echo "$date<br>";
}
$query = mysql_query("UPDATE table2,table1 SET table2.race_id=table1.id WHERE table2.venue=table1.venue AND table2.newdate='$date' AND newtime='$time2'");
?>

 

Hopefully someone can help.

Link to comment
https://forums.phpfreaks.com/topic/51840-solved-update-not-updating/
Share on other sites

Your update query doesn't look valid to me...I have never seen it done like that.

 

Replace the query line with the line below so you can catch the error...

$query = mysql_query("UPDATE table2,table1 SET table2.race_id=table1.id WHERE table2.venue=table1.venue AND table2.newdate='$date' AND newtime='$time2'")or die(mysql_error());

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.