Warning Message
Moderator: General Moderators
Warning Message
Hey All,
I'm a newbie and I'm getting the same Warning message:
Warning: Supplied argument is not a valid MySQL result resource in /home/sites/site190/web/test01.php on line 45
Warning: Supplied argument is not a valid MySQL result resource in /home/sites/site190/web/test01.php on line 53
Warning: Supplied argument is not a valid MySQL result resource in /home/sites/site190/web/test01.php on line 69
<?php
// Set the variables for the database access:
$Host = "localhost";
$User = "username";
$Password = "password";
$DBName = "databasename";
$TableName = "Stratosphere";
$CheckIn = "09/01/2002";
$CheckOut = "09/05/2002";
$Link = mysql_connect ($Host, $User, $Password);
$Query = "SELECT * from $TableName WHERE (Dates = '$CheckIn')";
$Query01 = "SELECT * from $TableName WHERE (Dates = '$CheckOut')";
$Query02 = "SELECT Price FROM $TableName WHERE (Dates BETWEEN '$CheckIn' AND '$CheckOut')";
$Result = mysql_db_query ($DBName, $Query, $Link);
$Result01 = mysql_db_query ($DBName, $Query01, $Link);
$Result02 = mysql_db_query ($DBName, $Query02, $Link);
// Create a table.
print ("<TABLE BORDER=1 WIDTH=\"20%\" CELLSPACING=1 CELLPADDING=1 ALIGN=LEFT>\n");
print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>Price</TD>\n");
print ("</TR>\n");
// Fetch the results from the database.
while ($Row = mysql_fetch_array ($Result)) {
print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>$Row[Price]</TD>\n");
print ("</TR>\n");
print "<p>Check In Day: $$Row[Price].00<br></p>\n";
}
// Fetch the results from the database01.
while ($Row = mysql_fetch_array ($Result01)) {
print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>$Row[Price]</TD>\n");
print ("</TR>\n");
print "<p>Check Out Day: $$Row[Price].00<br></p>\n";
}
print ("</TABLE>\n");
// Create a table.
print ("<TABLE BORDER=1 WIDTH=\"20%\" CELLSPACING=1 CELLPADDING=1 ALIGN=LEFT>\n");
print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>Price</TD>\n");
print ("</TR>\n");
while ($Row = mysql_fetch_array ($Result02)) {
print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>$Row[Price]</TD>\n");
print ("</TR>\n");
}
print ("</TABLE>\n");
$a = array($Query02);
echo "sum(a) = ".array_sum($a)."\n";
mysql_close ($Link);
?>
I have this working fine on my computer testing environment, IIS 5.0 , PHP 4.21.
But when I upload it to my web host I get the Warnings.
I can see that they are using PHP 4.12, I'm not sure if that makes a difference.
thanks for any help.
I'm a newbie and I'm getting the same Warning message:
Warning: Supplied argument is not a valid MySQL result resource in /home/sites/site190/web/test01.php on line 45
Warning: Supplied argument is not a valid MySQL result resource in /home/sites/site190/web/test01.php on line 53
Warning: Supplied argument is not a valid MySQL result resource in /home/sites/site190/web/test01.php on line 69
<?php
// Set the variables for the database access:
$Host = "localhost";
$User = "username";
$Password = "password";
$DBName = "databasename";
$TableName = "Stratosphere";
$CheckIn = "09/01/2002";
$CheckOut = "09/05/2002";
$Link = mysql_connect ($Host, $User, $Password);
$Query = "SELECT * from $TableName WHERE (Dates = '$CheckIn')";
$Query01 = "SELECT * from $TableName WHERE (Dates = '$CheckOut')";
$Query02 = "SELECT Price FROM $TableName WHERE (Dates BETWEEN '$CheckIn' AND '$CheckOut')";
$Result = mysql_db_query ($DBName, $Query, $Link);
$Result01 = mysql_db_query ($DBName, $Query01, $Link);
$Result02 = mysql_db_query ($DBName, $Query02, $Link);
// Create a table.
print ("<TABLE BORDER=1 WIDTH=\"20%\" CELLSPACING=1 CELLPADDING=1 ALIGN=LEFT>\n");
print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>Price</TD>\n");
print ("</TR>\n");
// Fetch the results from the database.
while ($Row = mysql_fetch_array ($Result)) {
print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>$Row[Price]</TD>\n");
print ("</TR>\n");
print "<p>Check In Day: $$Row[Price].00<br></p>\n";
}
// Fetch the results from the database01.
while ($Row = mysql_fetch_array ($Result01)) {
print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>$Row[Price]</TD>\n");
print ("</TR>\n");
print "<p>Check Out Day: $$Row[Price].00<br></p>\n";
}
print ("</TABLE>\n");
// Create a table.
print ("<TABLE BORDER=1 WIDTH=\"20%\" CELLSPACING=1 CELLPADDING=1 ALIGN=LEFT>\n");
print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>Price</TD>\n");
print ("</TR>\n");
while ($Row = mysql_fetch_array ($Result02)) {
print ("<TR ALIGN=CENTER VALIGN=TOP>\n");
print ("<TD ALIGN=CENTER VALIGN=TOP>$Row[Price]</TD>\n");
print ("</TR>\n");
}
print ("</TABLE>\n");
$a = array($Query02);
echo "sum(a) = ".array_sum($a)."\n";
mysql_close ($Link);
?>
I have this working fine on my computer testing environment, IIS 5.0 , PHP 4.21.
But when I upload it to my web host I get the Warnings.
I can see that they are using PHP 4.12, I'm not sure if that makes a difference.
thanks for any help.
quoting from the PHP manual about mysql_db_query:
Try fixing that and see if your error goes away.Note: This function has been deprecated since PHP 4.0.6. Do not use this function. Use mysql_select_db() and mysql_query() instead.
Last edited by llimllib on Mon Aug 19, 2002 1:35 pm, edited 1 time in total.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Instead of:
try
which should give you better error messages than the PHP generated one (because mysql_error() gives you the MySQL error message). You shouldn't use mysql_db_query() instead use mysql_select_db() and mysql_query().
Edit: slightly too slow on the mysql_db_query() thing (really should preview posts before submitting them) but the mysql_error() thingie still stands. Never hurts to have a lot of error trapping in your code.
Mac
Code: Select all
$Result = mysql_db_query ($DBName, $Query, $Link);
$Result01 = mysql_db_query ($DBName, $Query01, $Link);
$Result02 = mysql_db_query ($DBName, $Query02, $Link);Code: Select all
mysql_select_db($DBName) or die(mysql_error());
$Result = mysql_query ($Query) or die(mysql_error().'<br />'.$Query);
$Result01 = mysql_query ($Query01) or die(mysql_error().'<br />'.$Query01);
$Result02 = mysql_query ($Query02) or die(mysql_error().'<br />'.$Query02);Edit: slightly too slow on the mysql_db_query() thing (really should preview posts before submitting them) but the mysql_error() thingie still stands. Never hurts to have a lot of error trapping in your code.
Mac
Warning messages
Thanks, twigletmac.
That worked!!
I have another Newbie question.
I need to add up the values that are in that array.
The results I get are 34, 34, 34, 34, 34, 75.
I tried looking around for the SUM function, but I don't understand how to use it with an array.
thanks
That worked!!
I have another Newbie question.
I need to add up the values that are in that array.
The results I get are 34, 34, 34, 34, 34, 75.
I tried looking around for the SUM function, but I don't understand how to use it with an array.
thanks
at the beginning of the script, put Then, After every mysql_fetch_array(), do:At the end, $price will contain the sum of the prices.
Also, you should use $Row['price'] in place of $Row[price], and conventionally you use lowercase names for variables, reserving uppercase for function and class names.
Code: Select all
$price = 0;Code: Select all
$price = $price + $Rowї'Price'];Also, you should use $Row['price'] in place of $Row[price], and conventionally you use lowercase names for variables, reserving uppercase for function and class names.