SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    911
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Apostrophe causing problems in insert to database

    I have a particular field in a form that has an apostrphe in the title and when inserting into the database, I get the error relating to the apostrophe

    So I tried the code below, and its not working, could somebody take a look please.

    Code:
    $sql = mysql_query("INSERT INTO hazzard (name_db, project_db, company_db, contact_db, detail_db, Location_1, Location_2, Location_3) VALUES ('{$_SESSION['name_A']}','{$_SESSION['projects_A']}','{$_SESSION['companies_A']}','{$_SESSION['numbers_A']}','$detail','".mysql_real_escape_string{$_SESSION['top_A']}."','{$_SESSION['middle_A']}','{$_SESSION['bottom_A']}')") or die (mysql_error());
    Its where I am attempting to use mysql_real_escape_string

  2. #2
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    911
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the error I'm getting -

    Notice: Use of undefined constant mysql_real_escape_string - assumed 'mysql_real_escape_string' in E:\domains\a\page4.php on line 16
    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 's Building/Welcome Centre','Level 4','Riser')' at line 1

  3. #3
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,219
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    the following:
    PHP Code:
    mysql_real_escape_string{$_SESSION['top_A']} 
    Should be
    PHP Code:
    mysql_real_escape_string($_SESSION['top_A']) 

  4. #4
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    911
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh, thanks cpradio...

    The funny thing is at first I couldnt see the difference, but thanks again.

  5. #5
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,219
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    Yeah, that is a bit hard to distinguish, isn't it.


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
  •