Jump to content

Recommended Posts

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.");
}
?> 

Link to comment
https://forums.phpfreaks.com/topic/128462-solved-php-error/
Share on other sites

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.");


}

Link to comment
https://forums.phpfreaks.com/topic/128462-solved-php-error/#findComment-665802
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/128462-solved-php-error/#findComment-665999
Share on other sites

<?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.");
}
?>

Link to comment
https://forums.phpfreaks.com/topic/128462-solved-php-error/#findComment-666064
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/128462-solved-php-error/#findComment-666221
Share on other sites

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.