Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    May 2010
    Posts
    188
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Parse Error When I try to Insert an IP

    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)"
    ); 

  • #2
    Banned
    Join Date
    Mar 2013
    Posts
    139
    Thanks
    0
    Thanked 9 Times in 9 Posts
    $ip2 is a string and so needs to be enclosed in single quotes in your sql query statement.

  • #3
    Banned
    Join Date
    Mar 2013
    Posts
    139
    Thanks
    0
    Thanked 9 Times in 9 Posts
    and in your $ip2 declaration statement.

  • #4
    Regular Coder
    Join Date
    May 2010
    Posts
    188
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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. What is the problem?

  • #5
    Banned
    Join Date
    Mar 2013
    Posts
    139
    Thanks
    0
    Thanked 9 Times in 9 Posts
    you've done what I said in post 3. Have you done what I said in post 2?

  • #6
    Regular Coder
    Join Date
    May 2010
    Posts
    188
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok I solve it,thanks

    I put a quote in my insert statements, sometimes I am really forgetful of these syntax/rules

    PHP Code:
    mysql_query("INSERT INTO table_name(ip_string) 
       VALUES('$ip2')"
    ); 


  •  

    Posting Permissions

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