Jump to content

Recommended Posts

Trying to run a mysqli query inside another query and don't get past a single cycle. What wrong - I am a n00bie!

 

		$result = mysqli_query($db,"SELECT * FROM test WHERE active = 'y' AND expiredate < $todaydate") or die("<b>Error in Query</b>.\n<br>Error: " . mysqli_error($db));
		while ($row = mysqli_fetch_array($result)) {
		extract($row);  
			$query = "UPDATE test SET active='t' WHERE (id = '$id')";
			$result = mysqli_query($db,$query) or die("<b>Error in Query 3</b>.\n<br>Error: " . mysqli_error($db));
			echo "$fname $lname ($id) active status changed to n <br>"; 
			unset($fname, $lname, $email, $id, $expiredate);
			}

Gives me an error on the while statement (line 2) on second cycle. ???

Edited by WeBBy421

So there are many things that should be improved on here, but the answer to your question is that your original query either failed or didn't return any results. Tell us what the error actually is.

Having said that, there are some obvious things to do. First, make sure error reporting is turned on on your development machine so you can see when something goes wrong. Secondly, stop putting variables directly into your queries and use prepared statements. Finally, these two queries can easily be combined into one to save you resources and time.

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.