Jump to content

[SOLVED] Need help with a query


Cardale

Recommended Posts

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");
		}
  		}

Link to comment
https://forums.phpfreaks.com/topic/165882-solved-need-help-with-a-query/
Share on other sites

$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'

$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.

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.