WeBBy421 Posted May 16, 2022 Share Posted May 16, 2022 (edited) 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 May 16, 2022 by WeBBy421 Quote Link to comment https://forums.phpfreaks.com/topic/314798-running-a-mysqli-query-within-another-query/ Share on other sites More sharing options...
maxxd Posted May 16, 2022 Share Posted May 16, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/314798-running-a-mysqli-query-within-another-query/#findComment-1596303 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.