Jump to content

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());

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.