stevens Posted August 7, 2006 Share Posted August 7, 2006 Hi I am running the script below and it works perfectly (updates the database ok) yet displays the following error, please help me undertsand why. Thankyou.(The code is to be run by a cron job to check whether an account has expired)Error Message:[quote]PHP Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /2.php on line 9[/quote]Code:[quote]<?phpinclude("config.php");$connection = mysql_connect($hostname, $user, $pass) or die ("Unable to connect!");$query = "SELECT * FROM details WHERE order_no != 0";$result = mysql_db_query($db, $query, $connection) or die ("Could not execute query: $query. " . mysql_error());while ($newArray = mysql_fetch_assoc($result)) { $order_no = $newArray['order_no']; $word = $newArray['word']; $email = $newArray['cust_email']; $start_date = $newArray['start_date']; $end_date = $newArray['end_date']; $date = date("Y-m-d");if ($end_date == $date) {$query = "DO QUERY";$result = mysql_db_query($db, $query, $connection) or die ("Could not execute query: $query. " . mysql_error()); $subject = "YOUR ACCOUNT HAS NOW EXPIRED"; $msg = "THE ACCOUNT YOU HAVE PURCHASED ON ".$domain." HAS NOW EXPIRED\n\n"; mail($email, $subject, $msg, "From: ".$orderemail);} else {$days_left = (strtotime($end_date) - strtotime(date("Y-m-d"))) / (60 * 60 * 24);if ($days_left == '30') { $subject = "YOUR ACCOUNT IS EXPIRING IN 30 DAYS"; $msg = "THE ACCOUNT YOU HAVE PURCHASED ON ".$domain." IS EXPIRING IN 30 DAYS\n\n"; $msg.= "PLEASE LOGIN TO YOUR MEMBERS ACCOUNT NOW\n\n"; mail($email, $subject, $msg, "From: ".$orderemail);}}echo "$days_left";}?>[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/16803-simple-script-error-help-pls/ Share on other sites More sharing options...
Daniel0 Posted August 7, 2006 Share Posted August 7, 2006 Change mysql_db_query to mysql_query and then select a database right after connecting. Quote Link to comment https://forums.phpfreaks.com/topic/16803-simple-script-error-help-pls/#findComment-70710 Share on other sites More sharing options...
Orio Posted August 7, 2006 Share Posted August 7, 2006 I dont see you selecting a database.Orio. Quote Link to comment https://forums.phpfreaks.com/topic/16803-simple-script-error-help-pls/#findComment-70711 Share on other sites More sharing options...
spfoonnewb Posted August 7, 2006 Share Posted August 7, 2006 [quote]SELECT * FROM details [/quote] Quote Link to comment https://forums.phpfreaks.com/topic/16803-simple-script-error-help-pls/#findComment-70720 Share on other sites More sharing options...
wildteen88 Posted August 7, 2006 Share Posted August 7, 2006 [quote author=spfoonnewb link=topic=103293.msg411262#msg411262 date=1154963079][quote]SELECT * FROM details [/quote] [/quote]Thats not what orio ment,m that code doesnt select the database but queries the details table. He ment selecting mysql database using mysql_select_db('dbname_here');stevens I'd suggest you use:[code]$connection = mysql_connect($hostname, $user, $pass) or die ("Unable to connect!");mysql_select_db($db, $connection);$query = "SELECT * FROM details WHERE order_no != 0";$result = mysql_query($query, $connection) or die ("Could not execute query: $query. " . mysql_error());[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16803-simple-script-error-help-pls/#findComment-70724 Share on other sites More sharing options...
stevens Posted August 7, 2006 Author Share Posted August 7, 2006 Hi everyone and thanks for your help, Unfortunatly none of your answers worked.My database is being called in the config.php for you who were not sure.@wildteen I changed my code to what you posted but still got the same error - Isnt the code you posted the same as what i already had? thanks anyway.[size=18pt][color=red][b]EDIT: I HAVE SORTED IT NOW, I FOUND THE ERROR. THE ERROR WAS THE SECOND QUERY & RESULT NAME. I CHANGED IT TO QUERY2 & RESULT2 AND NO ERRORS ;D THANKS AGAIN FOR YOUR HELP GUYS[/b][/color][/size] Quote Link to comment https://forums.phpfreaks.com/topic/16803-simple-script-error-help-pls/#findComment-70823 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.