WEB PHP + MySQL query v. WTF

Discussion in 'OT Technology' started by Mikey, Feb 25, 2008.

  1. Mikey

    Mikey This one, this form I hold now, so Wide eyed and h

    Joined:
    Oct 18, 2001
    Messages:
    23,118
    Likes Received:
    0
    Location:
    Baltimore
    Ok, so I'm trying to query my forum database for all of the photos in the gallery table for a specific member. below is my code any help?

    Code:
    <?php
    
    include('header.php');
    include('include/gallery.functions.inc.php');
    
    
    $link = mysql_connect('hostname', 'user', 'password');
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
    echo 'Connected successfully';
    
    
    $user = "Mikey";
    $sql="SELECT 'thumb' FROM `xmb_imgimages` WHERE `author` = $user";
    $result = mysql_query($sql);
    echo "<img src='http://www.mydomain.com/" $result "'>";
    
    ?>
    it connects to the database fine, but is now returning an error of "Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /home/.heart/mikey/mydomain.com/memberphoto.php on line 20"
     
  2. JoeyJoJoJuniorShabadoo

    JoeyJoJoJuniorShabadoo Live Free or Die

    Joined:
    Nov 9, 2004
    Messages:
    4,347
    Likes Received:
    0
    Location:
    http://www.stogietime.com
    this line:

    echo "<img src='http://www.mydomain.com/" $result "'>";

    you mismatched the single and double quotes, change it to this:

    echo "<img src='http://www.mydomain.com/$result'>";

    that should work
     
  3. Fusion92

    Fusion92 New Member

    Joined:
    Oct 25, 2006
    Messages:
    36,856
    Likes Received:
    0
    Location:
    Toronto
    you didn't escape your quotes properly...the right way to do it would be
    echo "<img src=\"http://www.mydomain.com/\"$result>";
     
  4. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,915
    Likes Received:
    8
    Location:
    Los Angeles
    For the sake of a third solution...

    print '<img src="http://www.mydomain.com/"'.$result.' />';
     
  5. Mikey

    Mikey This one, this form I hold now, so Wide eyed and h

    Joined:
    Oct 18, 2001
    Messages:
    23,118
    Likes Received:
    0
    Location:
    Baltimore
    im sure that would help, but i noticed the data in "thumb" is not formatted in a way to be properly output to an img tag
     
  6. jdw

    jdw New Member

    Joined:
    Dec 31, 2005
    Messages:
    4,429
    Likes Received:
    0
    Location:
    ND
    what is the data?
     
  7. Mikey

    Mikey This one, this form I hold now, so Wide eyed and h

    Joined:
    Oct 18, 2001
    Messages:
    23,118
    Likes Received:
    0
    Location:
    Baltimore
    Code:
    gallery.php?action=viewthumb&amp;iid=1&amp;cid=1
     
  8. jdw

    jdw New Member

    Joined:
    Dec 31, 2005
    Messages:
    4,429
    Likes Received:
    0
    Location:
    ND
    There's gotta be a filename somewhere...

    what other columns in that table?
     
  9. noon

    noon get high and teach me how to listen

    Joined:
    May 4, 2002
    Messages:
    3,384
    Likes Received:
    0
    Location:
    Lawrence, KS
    youre ampersands are converting to &amp; so it's not linking right
     
  10. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,915
    Likes Received:
    8
    Location:
    Los Angeles
    IIRC, it'll still parse the &amp; as an ampersand because it's a GET var.
     
  11. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    shouldn't $user be in quotes?

    like this:

    Code:
    $sql="SELECT 'thumb' FROM `xmb_imgimages` WHERE `author` = '$user'"
    otherwise it thinks its a column name usually.
     
  12. lukin87

    lukin87 New Member

    Joined:
    Jan 11, 2008
    Messages:
    135
    Likes Received:
    0
    Code:
    <?php
    
    include('header.php');
    include('include/gallery.functions.inc.php');
    
    
    $link = mysql_connect('hostname', 'user', 'password');
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
    echo 'Connected successfully';
    
    
    $user = "Mikey";
    $sql="SELECT 'thumb' FROM `xmb_imgimages` WHERE `author` = $user";
    $result = mysql_query($sql);
    
    [I]while ($row = mysql_fetch_array($result)) {
       echo "<img src='http://www.mydomain.com/".$row['thumb']."'>";
    }[/I]
    
    ?>
    
    this will work. mysql_query returns a resource which isn't what you want to be printing. mysql_fetch_array parses the resource and returns an associative array containing the data from a single row of the query.

    probably not the best explanation, but i'm tired and there is a fuckton of information on it out on the web.

    the fix i've done should work,
     

Share This Page