Jump to content

SQL Query Error =/


adamh91

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.