Jump to content

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.

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.