www.webdeveloper.com
Results 1 to 3 of 3

Thread: Parse Error Inserting IP on the datae base

  1. #1
    Join Date
    May 2010
    Posts
    136

    Parse Error Inserting IP on the datae base

    Why do I get this parse error message when I try to insert an ip into the data base.

    Parse error: syntax error, unexpected T_DNUMBER
    Below is my code
    PHP Code:
     $ip2=219.90.90.2;
    $ip2=mysql_real_escape_string($ip2); 

    mysql_query("INSERT INTO table_name(ip_string)
       VALUES(
    $ip2)"); 
    Now if I try to put single or double quote like this
    PHP Code:
     $ip2='219.90.90.2' 
    the error will be gone, but it will not insert into the data base
    Last edited by anishgiri; 04-07-2013 at 10:47 PM.

  2. #2
    Join Date
    May 2010
    Posts
    136
    Ok I solve it I put a quote in my sql statement. Sometimes I am really forget full of these syntax/rules..

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,359
    Quote Originally Posted by anishgiri View Post
    Ok I solve it I put a quote in my sql statement. Sometimes I am really forget full of these syntax/rules..
    Moving up to either the MySQLi extension or the PDO extension (instead of using the deprecated MySQL extension) can help you avoid that sort of problem by making use of prepared statements. It also automatically takes care of any escaping.

    PHP Code:
    $sql "INSERT INTO table_name(ip_string) VALUES(?)";
    $stmt $mysqli->prepare($sql);
    $stmt->bind_param('s'$ip2); // handles all quoting/escaping issues for you
    $stmt->execute(); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles