RTS Posted May 16, 2007 Share Posted May 16, 2007 I have a project due tomorrow, and have been up til late working on this. can anyone tell me what is wrong with this code? This is the error I get 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 'from,message,date) VALUES ('p13','p13','jahjsbubf','May 15, 2007, 11:59 PM')' at line 1 for the code <?php session_start(); $text = $_POST['message']; $user = $_SESSION['username']; $user2 = $_GET['user']; $date = date('F j, Y, h:i A'); $con = mysql_connect("localhost","ZackBabtkis",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test", $con); mysql_query("INSERT INTO comments (username,from,message,date) VALUES ('$user2','$user','$text','$date')") or die('Error: ' . mysql_error()); mysql_close($con); header("location: /users/$user2"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/51618-please-help-really-frusterating-sql-error-on-something-due-tomorrow/ Share on other sites More sharing options...
AbydosGater Posted May 16, 2007 Share Posted May 16, 2007 Could you post your database table structure and what version of mysql are you running on? Andy Quote Link to comment https://forums.phpfreaks.com/topic/51618-please-help-really-frusterating-sql-error-on-something-due-tomorrow/#findComment-254289 Share on other sites More sharing options...
RTS Posted May 16, 2007 Author Share Posted May 16, 2007 I am running MYSQL 4.1.21, and my database has five fields: "id","username","from","message","date": id is int with an auto_increment, and the rest are just text. Quote Link to comment https://forums.phpfreaks.com/topic/51618-please-help-really-frusterating-sql-error-on-something-due-tomorrow/#findComment-254484 Share on other sites More sharing options...
SoulAssassin Posted May 16, 2007 Share Posted May 16, 2007 Try using these ``. Sometimes it helps. Like this: <?php session_start(); $text = $_POST['message']; $user = $_SESSION['username']; $user2 = $_GET['user']; $date = date('F j, Y, h:i A'); $con = mysql_connect("localhost","ZackBabtkis",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test", $con); mysql_query("INSERT INTO comments (`username`, `from`, `message`, `date`) VALUES ('$user2','$user','$text','$date')") or die('Error: ' . mysql_error()); mysql_close($con); header("location: /users/$user2"); ?> If not, post all the code. Maybe the problem is somewhere else. Quote Link to comment https://forums.phpfreaks.com/topic/51618-please-help-really-frusterating-sql-error-on-something-due-tomorrow/#findComment-254493 Share on other sites More sharing options...
RTS Posted May 16, 2007 Author Share Posted May 16, 2007 Yay that worked thanks so much. Quote Link to comment https://forums.phpfreaks.com/topic/51618-please-help-really-frusterating-sql-error-on-something-due-tomorrow/#findComment-254507 Share on other sites More sharing options...
SoulAssassin Posted May 17, 2007 Share Posted May 17, 2007 No problem, please remember to mark the thread as RESOLVED. Quote Link to comment https://forums.phpfreaks.com/topic/51618-please-help-really-frusterating-sql-error-on-something-due-tomorrow/#findComment-255143 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.