adamh91 Posted March 2, 2007 Share Posted March 2, 2007 Hey, Im trying to insert some values into my table, im getting this error and i cant see why =/ Error, insert 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 'use,to,from,message,subject,date) VALUES ('1','ALL','1','1','1','March 2, 2007, ' This code to insert: $subject = $_POST['subject']; $from = $_POST['from']; $message = $_POST['message']; $date = date("F j, Y, g:i a"); $conn = mysql_connect($db_host, $db_user, $db_pass) or die ('Error: '. mysql_error()); mysql_select_db($db_name); $query = "INSERT INTO history (use,to,from,message,subject,date) VALUES ('1','ALL','$from','$message','$subject','$date')"; mysql_query($query) or die('Error, insert query failed: ' . mysql_error()); Link to comment https://forums.phpfreaks.com/topic/40890-sql-query-error/ Share on other sites More sharing options...
redarrow Posted March 2, 2007 Share Posted March 2, 2007 addslashes and trim ok Link to comment https://forums.phpfreaks.com/topic/40890-sql-query-error/#findComment-198033 Share on other sites More sharing options...
adamh91 Posted March 2, 2007 Author Share Posted March 2, 2007 addslashes and trim ok can you explain sorry? thanks for the quick reply Link to comment https://forums.phpfreaks.com/topic/40890-sql-query-error/#findComment-198037 Share on other sites More sharing options...
spfoonnewb Posted March 2, 2007 Share Posted March 2, 2007 Your query was bugged somewhere.. it wouldn't work.... This should: <?php $subject = 'test'; $from = 'test'; $message = 'test'; $date = date("F j, Y, g:i a"); $subject = addslashes($subject); $subject = trim($subject); $from = addslashes($from); $from = trim($from); $message = addslashes($message); $message = trim($message); $date = addslashes($date); $date = trim($date); $conn = mysql_connect('localhost', 'test', 'test') or die ('Error: '. mysql_error()); mysql_select_db('test'); $q = mysql_query("INSERT INTO `history` ( `useq` , `to` , `from` , `message` , `subject` , `date` ) VALUES ( '1', 'ALL', '$from', '$message', '$subject', '$date' )"); if ($q) { echo "Ok"; } else { echo "Not OK"; } ?> Link to comment https://forums.phpfreaks.com/topic/40890-sql-query-error/#findComment-198065 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.