java12 Posted May 17, 2007 Share Posted May 17, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/51840-solved-update-not-updating/ Share on other sites More sharing options...
java12 Posted May 19, 2007 Author Share Posted May 19, 2007 Perhaps someone can point me in the right direction? Quote Link to comment https://forums.phpfreaks.com/topic/51840-solved-update-not-updating/#findComment-257148 Share on other sites More sharing options...
pocobueno1388 Posted May 19, 2007 Share Posted May 19, 2007 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()); Quote Link to comment https://forums.phpfreaks.com/topic/51840-solved-update-not-updating/#findComment-257152 Share on other sites More sharing options...
java12 Posted May 19, 2007 Author Share Posted May 19, 2007 Thanks pocobueno1338, though I don't actually get any errors as such. Now the table2 race_id field is updating....but only the venue fields are matching - the AND table2.newdate='$date' AND newtime='$time2' is being ignored by the query. Quote Link to comment https://forums.phpfreaks.com/topic/51840-solved-update-not-updating/#findComment-257180 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.