addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcredit-cardcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobe--smallglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1launch-new-window--smalllight-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Re: [php-49] sql error

From: max s.
Sent on: Monday, February 18, 2013 2:06 PM
I'm going to try to dig in to this this afternoon as I don't have school, just lots of homework which I do enjoy. This project is for a class, and I've already managed to build a working cart that mets my class requirements but it is super ugly so i'm trying to push through to something better. I do fear what Josh said flew right over my head though, but I'm going to try to dig in to it.

Thank you Josh.




On Feb 18, 2013, at 1:49 PM, Josh Young <[address removed]> wrote:

Well, without seeing more of your code, I can't tell you what exactly is wrong, but I'm pretty sure the error you are seeing is because you aren't checked to see that the query actually worked before iterating over it.

Basically, mysql_query will either return a resource which you can loop over or false if there was an error.
You are probably getting some kind of error and therefore $result is false.
So you are calling essentially calling mysql_fetch_assoc(false) which it doesn't understand.
I'd check the $result first to make sure it is something other than false and is ideally a proper resource.

A simple if($result) block wrapped around your while loop should prevent the error.

The reason for the error might be bad SQL or something else... can't tell for sure at this point.

Hope that helps.


From: max steinmetz <[address removed]>
To: [address removed]
Sent: Monday, February 18,[masked]:42 PM
Subject: [php-49] sql error

Hello, newb here with a question.

I'm attempting to build a simple shopping cart, this is my first time doing so and I am getting an error message which reads as follows:


Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in


Any help would be greatly appreciated as I'm google this error messag a bit and seen so many possible options that my mind turned to goop.

Again thank you for any help/direction possible.



This is the code starting with line #42

<div class="container">
<span class="top-label">
<span class="label-txt">PRODUCTS (TAKE Displayed things from here)</span>
</span>
<div class="content-area">
<div class="content drag-desired">
<?php
$result = mysql_query("SELECT * FROM internet_shop");
while($row=mysql_fetch_assoc($result))
{
echo '<div class="product"><img src="_img/products/'.$row['img'].'" alt="'.htmlspecialchars($row['name']).'" width="128" height="128" class="pngfix" /></div>';
}
?>
<div class="clear"></div>
</div>
</div>
<div class="bottom-container-border">
</div>
</div>





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by max steinmetz ([address removed]) from The Seattle PHP Meetup Group.
To learn more about max steinmetz, visit his/her member profile
Set my mailing list to email me As they are sent | In one daily email | Don't send me mailing list messages

Meetup, POB 4668 #37895 NY NY USA 10163 | [address removed]






--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Josh Young ([address removed]) from The Seattle PHP Meetup Group.
To learn more about Josh Young, visit his/her member profile
Set my mailing list to email me As they are sent | In one daily email | Don't send me mailing list messages

Meetup, POB 4668 #37895 NY NY USA 10163 | [address removed]

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy