Re: [php-49] sql error

From: Jd D.
Sent on: Monday, February 18, 2013 2:01 PM
If that doesn't work, open up a mysql terminal and try running that against your Database, make sure you set your Database correctly too =)


On Mon, Feb 18, 2013 at 1:59 PM, ehime-ken <[address removed]> wrote:
Here, use this instead =)

    <?php

        try {
            $hostname = "servername";
            $dbname = "dbname";
            $username = "username";
            $pw = "password";
            $pdo = new PDO ("mysql:host=$hostname;dbname=$dbname","$username","$pw");
          } catch (PDOException $e) {
            echo "Failed to get DB handle: " . $e->getMessage() . "\n";
            exit;
          }

          $query = $pdo->prepare("SELECT * FROM internet_shop");
          $query->execute();
        
          // more efficient than while =P
          for($i=0; $row = $query->fetch(); $i++){
            echo "<div class='product'>";
            echo "<img  src='_img/products/{$row['img']}'
                        alt='{$row['name']}'
                        width='128'
                        height='128'
                        class='pngfix'
                  />";
            echo "</div>";
          }

          unset($pdo);
          unset($query);

There's a good way to set PDO outside your script by uzup_13 at hotmail dot com on http://www.php.net/manual/en/pdo.query.php maybe try modeling how you do stuff from there =)


On Mon, Feb 18, 2013 at 1:48 PM, Mark Steudel <[address removed]> wrote:
Throw this in and see if it helps debug it:

$result = mysql_query("SELECT * FROM internet_shop");

if (!
$result) {
    die(
'Invalid query: ' mysql_error());
}


On Mon, Feb 18, 2013 at 1:43 PM, max steinmetz <[address removed]> wrote:
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]



--
-----------------------------------------
Mark Steudel
P: [masked]
F: [masked]
[address removed]

. : Adoption Updates : .
http://www.steudel.org/blog

. : Work : .
http://www.mindfulinteractive.com

. : LinkedIn : .
http://www.linkedin.com/in/steudel




--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Mark Steudel ([address removed]) from The Seattle PHP Meetup Group.
To learn more about Mark Steudel, visit his/her member profile



--
Jd Daniel || ERADO
Senior Applications Architect
7901 Delridge Way SW #36D, Seattle
C.    [masked]




--
Jd Daniel || ERADO
Senior Applications Architect
7901 Delridge Way SW #36D, Seattle
C.   [masked]

Our Sponsors

  • TUNE

    Meeting space and food

  • PluralSight

    PluralSight subscriptions for developer training

  • Siteground

    Information coming Soon

  • O'Reilly

    Disc Code: PCBW is good for 40% off print and 50% off ebooks and videos

  • JetBrains PhpStorm

    Occasional free licenses to raffle off at meetups

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