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 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2010
    Posts
    34
    Thanks
    22
    Thanked 0 Times in 0 Posts

    right syntax to use near '

    I must be getting burnt.

    Query 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 'from, subject, message, status) VALUES('sup01', 'orgadmin', 'dffgd', 'sdffdf', '' at line 1

    is generated from running:
    PHP Code:
    $sendTo $_POST['sendTo'];
    $subject $_POST['subject'];
    $message $_POST['message'];
    $from $_SESSION['username'];
    $status 'unread';


    $sql="INSERT INTO $tbl_name (sendTo, from, subject, message, status) VALUES('$sendTo', '$from', '$subject', '$message', '$status')";
    $result=mysql_query($sql) or die ("Query failed: " mysql_error());

    // if successfully insert data into database, displays message "Successful". 
    if($result){
    echo 
    "Successfully sent message";
    echo 
    "<BR>";
    echo 
    "<a href=\"javascript:history.go(-1)\">go back to the last page</a>";
    }

    else {
    echo 
    "ERROR";


  2. #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    17,027
    Thanks
    4
    Thanked 2,668 Times in 2,637 Posts
    This isn't a PHP error.
    FROM is a reserved word. If you use it as a field, then you must surround it with the backtick (`) character.

  3. Users who have thanked Fou-Lu for this post:

    thelung (08-07-2012)

  4. #3
    New Coder
    Join Date
    Sep 2010
    Posts
    34
    Thanks
    22
    Thanked 0 Times in 0 Posts
    i don't know what is wrong with me. Thank you.


 

Posting Permissions

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