MDanz Posted September 30, 2009 Share Posted September 30, 2009 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '12:36:06 WHERE name=Debate' at line 1 the variable $stackname comes from a while loop.. $stackname = $runrows['name']; i'm using it to update another table.. but it isn't updating? $query5= mysql_query("UPDATE castack SET recent=$time2 WHERE name='$stackname'")or die (mysql_error()); $time2 = $time['posted']; i don't see where i've gone wrong.. $time2 isn't a string so it should update heres the relevant part of code.. $construct = "SELECT * FROM `castack` WHERE $construct ORDER by recent DESC"; $stackname = $runrows['name']; $time = mysql_fetch_assoc($result); $time2 = $time['posted']; $timesince = strtotime($time['posted']); $posted = TimeSince::since($timesince); } $query5= mysql_query("UPDATE castack SET recent=$time2 WHERE name=$stackname")or die (mysql_error()); i've left out the for each loop, thats not the problem any help? Quote Link to comment https://forums.phpfreaks.com/topic/176047-solved-mysql-syntax-error/ Share on other sites More sharing options...
cags Posted September 30, 2009 Share Posted September 30, 2009 If $time2 is not an integer (which it isn't looking at your error message) then it should have single quotes around it. <?php $query5= mysql_query("UPDATE castack SET recent='$time2' WHERE name='$stackname'")or die (mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/176047-solved-mysql-syntax-error/#findComment-927624 Share on other sites More sharing options...
MDanz Posted September 30, 2009 Author Share Posted September 30, 2009 recent is DATETIME type in mysql... i can't put $time2 as a string? Quote Link to comment https://forums.phpfreaks.com/topic/176047-solved-mysql-syntax-error/#findComment-927626 Share on other sites More sharing options...
cags Posted September 30, 2009 Share Posted September 30, 2009 Erm.. why not? Did you try it? Quote Link to comment https://forums.phpfreaks.com/topic/176047-solved-mysql-syntax-error/#findComment-927630 Share on other sites More sharing options...
MDanz Posted September 30, 2009 Author Share Posted September 30, 2009 thx...ok i've changed some stuff around and got it displaying but not as i want itto? is there anything wrong with the last part of this.. $construct = "SELECT * FROM `castack` WHERE $construct ORDER by recent DESC"; it should display in order by most recent. The 'recent' column in mysql they all have type DATETIME and now i've gotten it to update .. this part of the code should make my results display according to that column.. but it's not.. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/176047-solved-mysql-syntax-error/#findComment-927633 Share on other sites More sharing options...
cags Posted September 30, 2009 Share Posted September 30, 2009 Have you got an example query string (ie what $construct looks like) and an example output thats not in the order you expect? Quote Link to comment https://forums.phpfreaks.com/topic/176047-solved-mysql-syntax-error/#findComment-927634 Share on other sites More sharing options...
MDanz Posted September 30, 2009 Author Share Posted September 30, 2009 4get got it working... thx for the help Quote Link to comment https://forums.phpfreaks.com/topic/176047-solved-mysql-syntax-error/#findComment-927635 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.