Cardale Posted July 14, 2009 Share Posted July 14, 2009 I have what feels like a stupid questions, but it is starting to irritate me since I can't figure it out. Can some one please point me in the right direction or tell me. I am getting a error with the delete query. What could be the problem? $sql_1 = "SELECT * FROM sessions"; $query_1 = $DB->query($sql_1) or die("c dont work"); while($row = $DB->fetch_array($query_1)){ $ip=$row["ip"]; $usertime=$row["time"]; $user_time_calc = strtotime($usertime); if($timeout_calc >= $user_time_calc){ $sql_2 = "DELETE FROM sessions WHERE ip=$ip"; $DB->query($sql_2) or die("a dont work"); } } Quote Link to comment https://forums.phpfreaks.com/topic/165882-solved-need-help-with-a-query/ Share on other sites More sharing options...
haku Posted July 14, 2009 Share Posted July 14, 2009 My magic ball tells me that the error is "you have screwed up somewhere". Am I close? Quote Link to comment https://forums.phpfreaks.com/topic/165882-solved-need-help-with-a-query/#findComment-874968 Share on other sites More sharing options...
megaresp Posted July 14, 2009 Share Posted July 14, 2009 $sql_2 = "DELETE FROM sessions WHERE ip=$ip"; Hi Cardale Try adding quotes around the variable $ip in the query, as follows... $sql_2 = "DELETE FROM sessions WHERE ip='$ip'"; NOTE: I haven't tested this. My reasoning is the IP address is a string (to MySQL), so must appear in quotes within the query. For example, MySQL would fail name=Bob but pass name='Bob' Quote Link to comment https://forums.phpfreaks.com/topic/165882-solved-need-help-with-a-query/#findComment-874995 Share on other sites More sharing options...
Cardale Posted July 14, 2009 Author Share Posted July 14, 2009 $sql_2 = "DELETE FROM sessions WHERE ip=$ip"; Hi Cardale Try adding quotes around the variable $ip in the query, as follows... $sql_2 = "DELETE FROM sessions WHERE ip='$ip'"; NOTE: I haven't tested this. My reasoning is the IP address is a string (to MySQL), so must appear in quotes within the query. For example, MySQL would fail name=Bob but pass name='Bob' haha Something tells me your magic ball was bought from the dollar store. That was it man. Good eye. Quote Link to comment https://forums.phpfreaks.com/topic/165882-solved-need-help-with-a-query/#findComment-875013 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.