MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old January 9th, 2004, 12:29 PM
aloo aloo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 26 aloo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
while($row = mysql_fetch_array($result))

hello everyone
im new to php so any help will be much appreciated
I have the error message:
Warning: mysql_fetch_row(): supplied argument is not has valid MySQL result resource line 38
and also
Warning: mysql_fetch_row(): supplied argument is not has valid MySQL result resource line 140

i have checked my database connection and that seems to be ok because my products.php works fine.


RemoveItem($_GET["itemId"]);
ShowCart();
break;
}
default:
{
ShowCart();
}
}
function AddItem($itemId, $qty)
{
global $dbServer, $dbUser, $dbPass, $dbName;
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);

$result = mysql_query("select count(*) from cart where cookieId = '" . GetCartID() . "' and itemId = $itemId");
$row = mysql_fetch_row($result); (line 38)
$numRows = $row[0];

if($numRows == 0)
{

@mysql_query("insert into cart(cookieID, itemId, qty) values('" . GetCartId() . "', $itemId, $qty)");
}
else
{
// This item already exists in the users cart,
// we will update it instead

UpdateItem($itemId, $qty);
}
}

function UpdateItem($itemId, $qty)
{

global $dbServer, $dbUser, $dbPass, $dbName;

// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
if($qty == 0)
{
// Remove the item from the users cart
RemoveItem($itemId);
}
else
{
mysql_query("update cart set qty = $qty where cookieId = '" . GetCartId() . "' and itemId = $itemId");
}
}

function RemoveItem($itemId)
{

global $dbServer, $dbUser, $dbPass, $dbName;

// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);

mysql_query("delete from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId");
}

function ShowCart()
{
// Gets each item from the cart table and display them in
// a tabulated format, as well as a final total for the cart

global $dbServer, $dbUser, $dbPass, $dbName;

// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);

$totalCost = 0;
$result = mysql_query("select * from cart inner join items on cart.itemId = item.itemId where cart.cookieId= '" . GetCartId() . "' order by item.name asc");
?>
<html>
<head>
<title> Your Shopping Cart </title>
<script language="JavaScript">

function UpdateQty(item)
{
itemId = item.name;
newQty = item.options[item.selectedIndex].text;

document.location.href = 'cart.php?action=update_item&id='+itemId+'&qty='+newQty;
}

</script>
</head>
<body bgcolor="#ffffff">
<h1>Your Shopping Cart</h1>
<form name="frmCart" method="get">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="15%" height="25" bgcolor="red">
<font face="verdana" size="1" color="white">
&nbsp;&nbsp;<b>Qty</b>
</font>
</td>
<td width="55%" height="25" bgcolor="red">
<font face="verdana" size="1" color="white">
<b>Product</b>
</font>
</td>
<td width="20%" height="25" bgcolor="red">
<font face="verdana" size="1" color="white">
<b>Price Each</b>
</font>
</td>
<td width="10%" height="25" bgcolor="red">
<font face="verdana" size="1" color="white">
<b>Remove?</b>
</font>
</td>
</tr>
<?php

while($row = mysql_fetch_array($result)) (line 140)
{
// Increment the total cost of all items
$totalCost += ($row["qty"] * $row["price"]);
?>

thanks

Reply With Quote
  #2  
Old January 9th, 2004, 12:43 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
In the past I've found Warning: mysql_fetch_row(): supplied argument is not has valid MySQL result generally means my query is wrong...
try outputting your SQL query to make sure it actually reads the way you want it to...

You may want to change this line to read:
$result = @mysql_query("select count(*) from cart where cookieId = '" . GetCartID() . "' and itemId = $itemId") or die("Error ".mysql_errno().": ".mysql_error());

Reply With Quote
  #3  
Old January 9th, 2004, 01:42 PM
aloo aloo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 26 aloo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i ve added the line of code you suggessted and know i get the following error

Error 1064: You have an error in your SQL syntax near '' at line 1

thanks

Reply With Quote
  #4  
Old January 9th, 2004, 05:49 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
check to make sure GetCartID() is returning the proper information... I would assume its not...

A common debugging technique that I use is to make the query a variable... it makes it easier to print if there's an error...

Based on the code I gave you before:

$sql="select count(*) from cart where cookieId = '" . GetCartID() . "' and itemId = $itemId";
$result = @mysql_query($sql) or die("Error ".mysql_errno().": ".mysql_error()."\nQuery: $sql");

bolding is there to show my changes...

Reply With Quote
  #5  
Old January 11th, 2004, 04:11 PM
aloo aloo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 26 aloo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks MadCowDzz

your debugging technique was helpful
i had a problem with my query.

It works now!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > while($row = mysql_fetch_array($result))


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway