error doubt

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Guest
Hi,

May i know whats wrong with my code.. when i display the products.php page.. these error shown...
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/eonenet/public_html/shopping_cart/products.php on line 24
* this is not the first time i encountered this..

i've checked my code and it should not have any prob coz i did assign a value for result variable,, but why i can't view the page.. did i miss something ???

please advise.


my db.php file ::::
Code:
<?

$dbserver = "";
$dbuser = "user";
$dbPass = "pass";
$dbName = "database";

function ConnectToDb($server, $user, $pass, $database)
{
	$s = @mysql_connect($server, $user, $pass);
	$d = @mysql_select_db($database, $s);

if (!$s || !$d)
	return false ; 
else
	return true ;
}



function GetCartId()
{
	//generate an encrypted string and set it as cookie
	if (isset($_cookie["cartId"]))
	{
		return $_cookie["cartId"];
	}
	else
	{
		session_start();
		setcookie("cartId", session_Id(), time() + ((3600 * 24) * 30));
		return session_id();
	}
}

?>



my products.php code:

Code:
<?

include ("db.php");

$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
$result = mysql_query("select * from items order by itemName asc");

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>

<table border="0">
<?php
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td width="30%" height="25">

<font face="Arial" size="1" color="black"><?php echo $row["itemName"]; ?>
</font>
</td>

<td width="10%" height="25">

<font face="arial" size="1" color="black"><?php echo $row["itemDesc"]; ?>
</font>
</td>

<td width="10%" height="25">

<font face="verdana" size="1" color="black"><a href ="cart.php?action=add_item&id=<?php echo $row["itemId"];?>&qty=1">Add Item 
</a></font>
</td>
        <td></td>
</tr>


<tr>
<td width="100%" colspan="4">
<hr size="1" color="red" NOSHADE>
</td>
</tr>

<tr>
<td width="100%" colspan="4">

<font face="arial" size="1" color="black"><a href="cart.php">Your shopping cart >> 
</a></font>
</td>
</tr>
<? } ?>
</table>
</BODY>
</HTML>
 
I would take the @ out so you can see what errors it is producing. Check servername, usernames, passwords, spelling in the database table and other such things.
 
or use next:
Code:
<?
$dbserver = "";
$dbuser = "user";
$dbPass = "pass";
$dbName = "database";

function ConnectToDb($server, $user, $pass, $database)
{
	$s = @mysql_connect($server, $user, $pass) or die("cannot connect to database<BR>MySQL said:" . mysql_error());
	$d = @mysql_select_db($database, $s);

if (!$s || !$d)
	return false ; 
else
	return true ;
}
 
echo mysql_error() will make life much easy... :idea: :arrow:
 
sigix said:
echo mysql_error() will make life much easy... :idea: :arrow:
i think what it's no matter.
who more like my propose shortest variant, who like youre variant more understanding....
Main result! :wink:
 
Back
Top