PDA

View Full Version : error in db[solved]


swissbeets
07-09-2008, 11:42 PM
am getting an error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\Copy (3) of website\shoppingcart.php on line 52

but i am pretty sure it should be fine because i copied this code from another place in my site

here is line 52 and anything else related:


$product_set = get_cart($setme);

while($row = mysql_fetch_array($product_set)) //<-----line 52
{
?>
<form method="POST" action="cart.php">
<input type="hidden" name="id" value="<?php echo $row['product_id']; ?>" />
<input type="submit" name="action" value="delete" />
<input type="hidden" name="price" value="<?php echo $row['product_price']; ?>" />
<p>
<?php echo $row['product_name']; ?><br />
$<?php echo $row['product_price']; ?><br /><br />
<?php show_picture($row); ?><br />
Size:
<p>
<select name="size">
<?php
$size = array('na'=>'Select','small'=>'S','medium'=>'M','large'=>'L','xlarge'=>'XL');
showOptionsDrop($size, $active);
?>
</select>
</p>
<input type="submit" value="Add to Shopping Cart" />
</p>
</form>
<?php
}
this is the function being called

function get_cart($cookie_id)
{

$cookie_id = 0;//THIS NEEDS SET TOO OR AT LEAST ERASED
global $connection;
$query = "SELECT *
FROM carts ";
//WHERE cookie_id = ".$cookie_id
$cart_set = mysql_query($query);
return $product_set;
confirm_query($product_set);

}

the cookie_id will be set at a later date but i dont see how that will be a problem, in the database the cookie id is nothing at all

davidj
07-10-2008, 06:44 AM
check your query

echo the query out and paste it into your mysql manager to see if it runs

double check all db fields and that you have spelt them correctly in your query

swissbeets
07-10-2008, 05:04 PM
this is the query i am getting

SELECT `image_source` FROM `products` WHERE 'product_id' =10

this is why i cannot figure it out because the query looks fine and everything lokos fine but the picture doesnt work and says the image source is images/%S

davidj
07-10-2008, 06:22 PM
you need to post all the code

swissbeets
07-10-2008, 06:44 PM
$cart_set = get_cart($setme);

while($row = mysql_fetch_array($cart_set))
{
$picture = $row['product_id'];
$query = "SELECT `image_source`
FROM `products` WHERE 'product_id' =". $picture;
echo $query;

$result = mysql_query($query, $connection) or die("Could not execute query " . mysql_errno());

$record = mysql_fetch_array($result) or die(sprintf("Could not execute query (%d): %s", mysql_errno(), mysql_error()));

show_picture($record);


the getcart is

function get_cart($cookie_id)
{

$cookie_id = 0;//THIS NEEDS SET TOO OR AT LEAST ERASED
global $connection;
$query = " SELECT *
FROM `cart`
LIMIT 0 , 30 ";
//WHERE cookie_id = ".$cookie_id
$cart_set = mysql_query($query);
return $cart_set;
confirm_query($cart_set);

}


the showpicture is

function show_picture($sel_product)
{
$picture = "images/ " . $sel_product['image_source'];
mysql_prep($picture);
?><img src="<?php print $picture;?> "width="120" height="120">
<?php
}

davidj
07-10-2008, 06:50 PM
this is very confusing

you need to echo out your query string to the page so you can see if its being set correctly

davidj
07-10-2008, 06:51 PM
did you write this yourself or have you copied it from somewhere

swissbeets
07-10-2008, 06:52 PM
wrote it myself but got help on this


echo $query;

$result = mysql_query($query, $connection) or die("Could not execute query " . mysql_errno());

$record = mysql_fetch_array($result) or die(sprintf("Could not execute query (%d): %s", mysql_errno(), mysql_error()));

show_picture($record);



this is what i get when i echo the query but it still doesnt work

SELECT `image_source` FROM `products` WHERE 'product_id' =10

Could not execute query (0):

davidj
07-10-2008, 07:02 PM
you need to copy that SQL into your mysql client IDE

SELECT `image_source` FROM `products` WHERE 'product_id' =10

and see if it runs

its escaping the SQL and dropping into the error but its not reporting which error so this leads me to believe its your syntax

i cant test it so will have to wait to see if someone pops by to do this

swissbeets
07-10-2008, 07:12 PM
you are right, it is returning nothing since my product_id is a int, does that change anything?

swissbeets
07-10-2008, 07:23 PM
got it!

this query worked
SELECT image_source FROM `products` WHERE product_id= 10

but this one doesnt

SELECT `image_source` FROM `products` WHERE 'product_id'= 8

it was the ''

davidj
07-10-2008, 11:01 PM
great news

swissbeets
07-10-2008, 11:02 PM
thank you very much