SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2004
    Location
    UK
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Quick php/mysql question.

    hi, im trying to enter some values into my database vis my script im using this peice of code.

    Code:
    $sqlrun = "INSERT INTO 'netboomy_links.linkinfo' ('url' ,'decr' ) VALUES ('$_POST[url]', '$_POST[discription]') ";
    
    echo "Sql Query";
    echo $sqlrun;
    
    if(!mysql_db_query("netboomy_links",$sqlrun,$dbh)) die(mysql_error());
    and im getting an error msg

    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 ''netboomy_links.linkinfo' ('url' ,'decr' ) VALUES ('http://www.PleaseWork.com', ' at line 1

    I've had a play around with it but cant seem to see what is wrong with it. any help would be great.

  2. #2
    SitePoint Addict
    Join Date
    May 2005
    Location
    London, ON
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try removing the quotes in the first part:

    PHP Code:
    $url mysql_real_escape_string($_POST['url']);
    $desc mysql_real_escape_string($_POST['description']);
    $sqlrun "INSERT INTO netboomy_links.linkinfo (url ,decr ) VALUES ('".$url."', '".$desc."') "
    I also added some security. Any time you're using input from another location you should escape it.
    Ryan Price
    Subscribe to my blog for regular tips and tricks

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2004
    Location
    UK
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Jean, the code you gave worked first time.. I just want to know whats the differance between these 2 lines

    $sqlrun = "INSERT INTO 'netboomy_links.linkinfo' (url ,decr) VALUES ('$_POST[url]', '$_POST[discription]') ";

    //$sqlrun = "INSERT INTO netboomy_links.linkinfo (url ,decr ) VALUES ('".$url."', '".$discription."') ";

    I took out the quotes on the first part like you suggested. im guessing you cant then use the $_POST global variables to do this? just want to get it clear in my head why it isnt working?

    cheers

    darren.

  4. #4
    Passionate Web Developer Egyptechno's Avatar
    Join Date
    Jan 2004
    Location
    Dubai
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    'netboomy_links.linkinfo'
    you don't write table name between single qoutes .. you write it directly or between those ` `
    I adore PHP

  5. #5
    SitePoint Addict
    Join Date
    May 2005
    Location
    London, ON
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Darren Tidmarsh View Post
    Thanks Jean, the code you gave worked first time.. I just want to know whats the differance between these 2 lines

    $sqlrun = "INSERT INTO 'netboomy_links.linkinfo' (url ,decr) VALUES ('$_POST[url]', '$_POST[discription]') ";

    //$sqlrun = "INSERT INTO netboomy_links.linkinfo (url ,decr ) VALUES ('".$url."', '".$discription."') ";

    I took out the quotes on the first part like you suggested. im guessing you cant then use the $_POST global variables to do this? just want to get it clear in my head why it isnt working?

    cheers

    darren.
    You're looking at the wrong spot. The table name and values immediately following those don't need to be quoted. It is only the items in in the VALUES (....) section that need the quotes
    Ryan Price
    Subscribe to my blog for regular tips and tricks

  6. #6
    An average geek earl-grey's Avatar
    Join Date
    Mar 2005
    Location
    Ukraine
    Posts
    1,403
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Egyptechno View Post
    Code:
    'netboomy_links.linkinfo'
    you don't write table name between single qoutes .. you write it directly or between those ` `
    You can't use single quotes around table name, but you can use backticks or, in ANSI SQL mode, double quotes.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •