1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Hmm. Where is the error?

Discussion in 'PHP' started by RyanDoubleyou, Aug 24, 2008.

  1. #1
    Hi, I know this is an easy fix, but I'm tired, so I cant seem to find it. Heres my code. I know it had something to do with my mysql query. Its for my website, http://tenimizer.com
    
    $usernameid = $_GET["extra"];
    $findboard = mysql_query("SELECT * FROM boards WHERE to='$usernameid'") or die(mysql_error());
    while($fb = mysql_fetch_array($findboard)) {
    
    PHP:
    Here's my error:

    
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'to=Ryan' at line 1
    
    Code (markup):
    Please help.
     
    RyanDoubleyou, Aug 24, 2008 IP
  2. xde5igner.com

    xde5igner.com Well-Known Member

    Messages:
    82
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    113
    Digital Goods:
    1
    #2
    $findboard = mysql_query("SELECT * FROM boards WHERE to=$usernameid") or die(mysql_error());

    and if this not work, then i think in the database you have set the type (integer/INT) of field (to)

    Regards
     
    xde5igner.com, Aug 24, 2008 IP
  3. ForumJoiner

    ForumJoiner Active Member

    Messages:
    762
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    83
    #3
    ForumJoiner, Aug 24, 2008 IP
  4. RyanDoubleyou

    RyanDoubleyou Peon

    Messages:
    86
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thank you both of you. Will try in morning. It's 3am here.
     
    RyanDoubleyou, Aug 24, 2008 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    You can do either that, or wrap the word into backticks.
    
    SELECT * FROM boards WHERE `to` = '$usernameid'
    
    Code (sql):
    Ah yeah, and ESCAPE YOUR INPUT:
    
    $usernameid = mysql_real_escape_string($_GET["extra"]);
    
    PHP:
    Today's homework is reading this page: www.php.net/mysql_real_escape_string
     
    nico_swd, Aug 24, 2008 IP
  6. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #6
    Full example:

    
    $usernameid = mysql_real_escape_string($_GET["extra"]);
    $findboard = mysql_query("SELECT * FROM boards WHERE `to`='" . $usernameid . "'") or die(mysql_error());
    while($fb = mysql_fetch_array($findboard)) {
    }
    
    Code (markup):
    Please don't add $variables within a string, better to add them as displayed above!
     
    EricBruggema, Aug 24, 2008 IP
  7. RyanDoubleyou

    RyanDoubleyou Peon

    Messages:
    86
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hi, Yes, I did the Real_escape_string, just didnt include it in here, also, changing the word to, to something like boardTo, worked great, and fixed the problem. Thanks everyone! - http://tenimizer.com
     
    RyanDoubleyou, Aug 24, 2008 IP