Clinton Posted January 30, 2013 Share Posted January 30, 2013 I seriously can't figure this out. Code: <?php session_start(); if(!isset($_SESSION['me'])) { header("location:index.php"); } $action=$_POST["action"]; $from=$_POST["name"]; $message=$_POST["message"]; $when=$_POST["when"]; echo $action . "<p>"; echo $from . "<p>"; echo $message . "<p>"; echo $when . "<p>"; if ($action == "add") { mysql_connect("localhost", "name", "name") or die(mysql_error()); mysql_select_db("name") or die(mysql_error()); mysql_query("INSERT INTO tweet(from,when,message)VALUES('$from','$when','$message')") or die(mysql_error()); header("location:home.php"); } ?> Produces: add blah@gmail.com Mary had a little lamb its fleece was white as snow. 2013-01-29 19:13:31 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,when,message)VALUES('blah@gmail.com','2013-01-29 19:13:31','Mary ha' at line 1 I'm beating my head. I can't fricken figure it out. Where's the error? Everything it's echoing is exactly what I'm putting into the system so the error isn't there. But where might it be? Any help appreciated. Thank you. CJA Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 30, 2013 Share Posted January 30, 2013 From is a restricted keyword. Quote Link to comment Share on other sites More sharing options...
Barand Posted January 30, 2013 Share Posted January 30, 2013 (edited) as is "when" You need to rename the columns (recommended) or use backticks eg `when` and `from` Edited January 30, 2013 by Barand Quote Link to comment Share on other sites More sharing options...
Clinton Posted January 30, 2013 Author Share Posted January 30, 2013 LoL. I should've known. In fact, I thought it was message (which I previously had abreviated as MSG). I was just searching the wrong way. http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html Thanks! CJA Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.