SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    May 2007
    Location
    Kent in Uk
    Posts
    538
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Strange SQL syntax problem

    Hi
    I am using a mysql databse on a windows platform. I am testing by connecting to my remote database. I am trying to create a primitive content management system where users can fill in a form and the information provided is placed into my database. Everything seems fine except I get this error message:

    Insertion into Database Failed:

    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 'niknbren@btinternet.com',1,'Cat illness','Cat territories', 'Cats rule ok' )' at line 4.

    It seems to be picking up on the words I have entered into the text boxes to be entered into the database. Line 4 in in the processForm page (seperate to the actual form) is
    PHP Code:
     $address $_POST['address']; 
    So I am a little mystified as to what I am doing wrong. The php form processing bit is as follows:

    PHP Code:
    <?php $connection mysqli_connect("91.186.30.8""louandel""13sunshine""cass27_louandel");
    $first_name $_POST['first_name'];
    $surname $_POST['surname'];
    $address $_POST['address'];
    $town $_POST['town'];
    $county $_POST['county'];
    $post_code $_POST['post_code'];
    $email =  $_POST['email'];
    $age $_POST['age'];
    $summary $_POST['summary'];
    $title $_POST['title'];
    $article $_POST['article'];
    $query "INSERT INTO articleform (
    first_name,surname,address,town,county,post_code,email,age,summary,title,article
    ) Values (
    '
    {$first_name}','{$surname}','{$address}','{$town}','{$county}','{$post_code}',''{$email}',{$age},'{$summary}','{$title}',
    '
    {$article}'
    )"
    ;
    $result mysqli_query($connection$query);
     if(
    $result){
     
    header("Location:contactSoon.php");
     exit;
     }else{
     echo 
    "<p>Insertion into Database Failed</p>";
      echo 
    "<p>".mysqli_error($connection)."</p>";
      }
    ?>
    anyone got any ideas?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    look at where the error message is telling you that the error occurred -- on the value for your email

    now look at your INSERT statement VALUES clause near the email value

    notice anything unusual?

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Evangelist
    Join Date
    May 2007
    Location
    Kent in Uk
    Posts
    538
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep your right. Tried it again without the extra ' but im afraid came up with exactly the same error message

    help!

  4. #4
    SitePoint Evangelist
    Join Date
    May 2007
    Location
    Kent in Uk
    Posts
    538
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aha! You were right. I forgot to refresh the process page on the local server. It works! I am an idiot and you, r937 have the brain the size of a planet.

    Thanks for your help.


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
  •