Jump to content

[SOLVED] PHP Error


jj20051

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.