Browser specific error

Discussion in 'PHP' started by JohnUK, May 23, 2009.

  1. #1
    Hi guys!

    I know this shouldnt happen but ive got a mysql error but only in google chrome and I presume safari. Its strange because the page shows correctly in all browsers despite the error :s

    here is the 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 '(email, password, first, sur, contact) VALUES ('','d41d8cd98f00b204e9800998ecf84' at line 1

    email should have a value going into it as well. This error is only seen in the source on chrome but not in the ie ff source. And the values go into the table as well.

    Any ideas how to fix this? Ive echoed the email address to screen and it is their.

    insert code:

    mysql_query("INSERT INTO $_POST[table] (email, password, first, sur, contact) VALUES ('$_POST','".md5($_POST['pass'])."','$_POST[first]','$_POST[sur]','$_POST[contact]')")or die(mysql_error());

    Any help?

    Cheers,

    J
     
    JohnUK, May 23, 2009 IP
  2. octalsystems

    octalsystems Well-Known Member

    Messages:
    352
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    135
    Digital Goods:
    1
    #2
    try to use like this

    mysql_query("INSERT INTO $_POST[table] (`email`, `password`, `first`, `sur`, `contact`) VALUES ('" .mysql_real_escape_string($_POST) ."','".md5($_POST['pass'])."','". mysql_real_escape_string($_POST[first]). "','". mysql_real_escape_string($_POST[sur]). "','". mysql_real_escape_string($_POST[contact]). "')")or die(mysql_error());
     
    octalsystems, May 23, 2009 IP
  3. JohnUK

    JohnUK Peon

    Messages:
    178
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi mate. Nope, another good effort. Error now:

    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 '(`email`, `password`, `first`, `sur`, `contact`) VALUES ('','d41d8cd98f00b204e98' at line 1

    page still loads and inserts data. Any other ideas?
     
    JohnUK, May 23, 2009 IP
  4. octalsystems

    octalsystems Well-Known Member

    Messages:
    352
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    135
    Digital Goods:
    1
    #4
    do u mean that query executes and stil gives error?

    ok do like this so i can see the full error query

    $cmd="INSERT INTO $_POST[table] (`email`, `password`, `first`, `sur`, `contact`) VALUES ('" .mysql_real_escape_string($_POST) ."','".md5($_POST['pass'])."','". mysql_real_escape_string($_POST[first]). "','". mysql_real_escape_string($_POST[sur]). "','". mysql_real_escape_string($_POST[contact]). "')"
    mysql_query($cmd)or die(mysql_error().$cmd);
     
    octalsystems, May 23, 2009 IP
  5. JohnUK

    JohnUK Peon

    Messages:
    178
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    now the error is:

    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 '(`email`, `password`, `first`, `sur`, `contact`) VALUES ('','d41d8cd98f00b204e98' at line 1INSERT INTO (`email`, `password`, `first`, `sur`, `contact`) VALUES ('','d41d8cd98f00b204e9800998ecf8427e','','','')

    its strange. if you echo any of the variables to screen it works fine.
     
    JohnUK, May 23, 2009 IP
  6. JohnUK

    JohnUK Peon

    Messages:
    178
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    forgot to say the values still go into db and page loads fine still.
     
    JohnUK, May 23, 2009 IP
  7. octalsystems

    octalsystems Well-Known Member

    Messages:
    352
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    135
    Digital Goods:
    1
    #7
    now see here

    INSERT INTO <MISSING TABLE NAME> (`email`, `password`, `first`, `sur`, `contact`) VALUES ('','d41d8cd98f00b204e9800998ecf8427e','','','')
     
    octalsystems, May 23, 2009 IP
  8. JohnUK

    JohnUK Peon

    Messages:
    178
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Not sure whats going on. If I hardcode it the code works. Also If I look at the code the variables arent in the source code.

    Chrome: <input type="hidden" name="table" value="" />
    <input type="hidden" name="email" value="" />

    IE & FF: <input type="hidden" name="table" value="reps" />
    <input type="hidden" name="email" value="av1bbatey@hotmail.com" />

    Yet both can echo the variables to the screen! whats going on!!! :s
     
    JohnUK, May 23, 2009 IP
  9. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #9
    you should never pass table variables through that way...It can lead to being hacked quite easily...ALWAYS hardcode them in some way or in a way no one can alter them.
     
    NatalicWolf, May 23, 2009 IP
  10. octalsystems

    octalsystems Well-Known Member

    Messages:
    352
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    135
    Digital Goods:
    1
    #10
    what is the page url?
     
    octalsystems, May 23, 2009 IP
  11. JohnUK

    JohnUK Peon

    Messages:
    178
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    NatalicWolf - How can they hack it? I guess they could create a new file to the same page and fill in the values that they wanted but any table that doesnt exist will just error right? And I can put anti injection code to stop them trying to remove data.

    octal - thanks I will PM you the url.
     
    JohnUK, May 24, 2009 IP