jj20051 Posted October 15, 2008 Share Posted October 15, 2008 Ok I Built A Simple Billing Script, but I Get This Error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/billing2/public_html/email.php on line 14 Here Is The Script Code: <?php $dbhost = 'localhost'; $dbuser = 'billing2_admin'; $dbpass = 'a3a471'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'billing2_ptc'; mysql_select_db($dbname); $day=date("j"); $sql="SELECT * FROM `invoices` WHERE `day`={$day}"; $query=mysql_query($sql); while ($req=mysql_fetch_array($query)) { mail($req['UserEmail'], "You must pay for protection.", "You haven't paid for protection. You have one day to pay or god may strike down your building."); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/128462-solved-php-error/ Share on other sites More sharing options...
Lamez Posted October 15, 2008 Share Posted October 15, 2008 change <?php $sql="SELECT * FROM `invoices` WHERE `day`={$day}"; while ($req=mysql_fetch_array($query)) { ?> to <?php $sql=mysql_query("SELECT * FROM `invoices` WHERE `day`={$day}"); while ($req=mysql_fetch_array($sql)) { ?> Quote Link to comment https://forums.phpfreaks.com/topic/128462-solved-php-error/#findComment-665707 Share on other sites More sharing options...
MadTechie Posted October 15, 2008 Share Posted October 15, 2008 i assume it a date problem but try this to check $query=mysql_query($sql) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/128462-solved-php-error/#findComment-665709 Share on other sites More sharing options...
jj20051 Posted October 15, 2008 Author Share Posted October 15, 2008 Ok With That It Says The Query Was Empty ( The or die Strand ) Quote Link to comment https://forums.phpfreaks.com/topic/128462-solved-php-error/#findComment-665785 Share on other sites More sharing options...
Lamez Posted October 15, 2008 Share Posted October 15, 2008 when in doubt echo out! echo out $day! Quote Link to comment https://forums.phpfreaks.com/topic/128462-solved-php-error/#findComment-665792 Share on other sites More sharing options...
jj20051 Posted October 15, 2008 Author Share Posted October 15, 2008 Well The Day String Does Exactly What I Wanted It To Do... Spits Out The Number 14, Witch Is Today's Date... Quote Link to comment https://forums.phpfreaks.com/topic/128462-solved-php-error/#findComment-665794 Share on other sites More sharing options...
Lamez Posted October 15, 2008 Share Posted October 15, 2008 ok in your query take out the {} and replace them with ' ' so like this: $sql="SELECT * FROM `invoices` WHERE `day`= '$day'"; Quote Link to comment https://forums.phpfreaks.com/topic/128462-solved-php-error/#findComment-665796 Share on other sites More sharing options...
jj20051 Posted October 15, 2008 Author Share Posted October 15, 2008 Same Thing, It Spits Out The Date and Says Query Is Empty... Quote Link to comment https://forums.phpfreaks.com/topic/128462-solved-php-error/#findComment-665798 Share on other sites More sharing options...
PFMaBiSmAd Posted October 15, 2008 Share Posted October 15, 2008 Start by posting your current actual code. The error does not mean a query with zero rows in it. It means no SQL statement was sent to the mysql server. Quote Link to comment https://forums.phpfreaks.com/topic/128462-solved-php-error/#findComment-665799 Share on other sites More sharing options...
jj20051 Posted October 15, 2008 Author Share Posted October 15, 2008 I Pretty Much Figured On That Much ( I Send 0's All The Time with No Problems ) Here Is My Current Code Minus The Database Connection... $day=date("j"); echo "$day"; $sql=mysql_query("SELECT * FROM invoices WHERE day='$day'"); $query=mysql_query($sql) or die(mysql_error()); while ($req=mysql_fetch_array($sql)) { mail($req['UserEmail'], "You must pay for protection.", "You haven't paid for protection. You have one day to pay or god may strike down your building."); } Quote Link to comment https://forums.phpfreaks.com/topic/128462-solved-php-error/#findComment-665802 Share on other sites More sharing options...
MadTechie Posted October 15, 2008 Share Posted October 15, 2008 No no.. your querying a result change to this <?php $day=date("j"); $sql="SELECT * FROM invoices WHERE day='$day'"; $query=mysql_query($sql) or die($sql.mysql_error()); while ($req=mysql_fetch_array($query)) { mail($req['UserEmail'], "You must pay for protection.", "You haven't paid for protection. You have one day to pay or god may strike down your building."); } ?> if you get an error please give us that exact error Quote Link to comment https://forums.phpfreaks.com/topic/128462-solved-php-error/#findComment-665999 Share on other sites More sharing options...
Andy-H Posted October 15, 2008 Share Posted October 15, 2008 <?php $day=date("j"); $sql="SELECT * FROM invoices WHERE day='$day'"; $query=mysql_query($sql) or die($sql.mysql_error()); while ($req=mysql_fetch_array($query) && mysql_num_rows($query) != 0) { mail($req['UserEmail'], "You must pay for protection.", "You haven't paid for protection. You have one day to pay or god may strike down your building."); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/128462-solved-php-error/#findComment-666064 Share on other sites More sharing options...
jj20051 Posted October 15, 2008 Author Share Posted October 15, 2008 Good News and Bad News... The Script No Longer Spits Out An Error, but It Doesn't Send The Email Out Either... Quote Link to comment https://forums.phpfreaks.com/topic/128462-solved-php-error/#findComment-666167 Share on other sites More sharing options...
jj20051 Posted October 15, 2008 Author Share Posted October 15, 2008 Good News and Bad News... The Script No Longer Spits Out An Error, but It Doesn't Send The Email Out Either... Quote Link to comment https://forums.phpfreaks.com/topic/128462-solved-php-error/#findComment-666214 Share on other sites More sharing options...
DoddsAntS Posted October 15, 2008 Share Posted October 15, 2008 have a try of the following <?php $day=date("j"); $sql="SELECT * FROM invoices WHERE day='$day'"; $query=mysql_query($sql) or die($sql.mysql_error()); if(mysql_num_rows($query) > 0) { while ($req=mysql_fetch_array($query)) { if(mail($req['UserEmail'], "You must pay for protection.", "You haven't paid for protection. You have one day to pay or god may strike down your building.")) { echo "Sent email to {$req['UserEmail']}\n<br />\n"; } else { echo "Failed to send email to {$req['UserEmail']}\n<br />\n"; } } } else { echo "No results!"; } ?> Regards, A Quote Link to comment https://forums.phpfreaks.com/topic/128462-solved-php-error/#findComment-666221 Share on other sites More sharing options...
jj20051 Posted October 15, 2008 Author Share Posted October 15, 2008 Thank You So Much, I Was Beggining To Feel Like I Would Never Get It To Work... Quote Link to comment https://forums.phpfreaks.com/topic/128462-solved-php-error/#findComment-666227 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.