gs Posted August 17, 2008 Share Posted August 17, 2008 Hi, I really need some help with this, Ive been trying to figure it out for such a long time! Ok, I want this to connect to the database, and then insert info into the table, which I already have created. Here is the exact script: <?php $username = $_COOKIE['ID_my_site']; $msg = $_POST['message']; $to = $_POST['to']; mysql_connect("freshsql.com","username","password")or die("SQL Error".mysql_error());; mysql_select_db("data1")or die("SQL Error".mysql_error());; $query="INSERT INTO messages(username,from,message) VALUES('$to',$username','$msg')"; mysql_query($query)or die("SQL Error".mysql_error()); ?> It keeps returning an error: "SQL ErrorYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''messages'(username,from,message) VALUES('gs',gs','gsaafd')' at line 1" Please help! I cannot figure this out, Thanks -GS EDIT: Use meaningful topic subject names and post in the correct forum. Link to comment https://forums.phpfreaks.com/topic/120030-solved-mysql-insert-problem/ Share on other sites More sharing options...
toplay Posted August 17, 2008 Share Posted August 17, 2008 Change this: $query="INSERT INTO messages(username,from,message) VALUES('$to',$username','$msg')"; To this: $query="INSERT INTO messages(`username`,`from`,`message`) VALUES('$to','$username','$msg')"; Link to comment https://forums.phpfreaks.com/topic/120030-solved-mysql-insert-problem/#findComment-618324 Share on other sites More sharing options...
gs Posted August 17, 2008 Author Share Posted August 17, 2008 Yes!!! It worked! Thank you VERY much! I have been trying to figure this out for SOOO LONG! Thanks very much! Link to comment https://forums.phpfreaks.com/topic/120030-solved-mysql-insert-problem/#findComment-618327 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.