Posting data to the database
Posted: Fri Feb 04, 2011 4:26 pm
I have a simple php code to post information into my database table named mail.
For some reason I keep getting this 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 'to, from, subject, message) VALUES('tara2', 'tara', 'test', 'dflakjhdfkjhsldjk' at line 1"
The variables are passing correctly because they print out onto the screen. I feel like it's something silly I'm missing but I just don't see it.
Here's my code:
For some reason I keep getting this 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 'to, from, subject, message) VALUES('tara2', 'tara', 'test', 'dflakjhdfkjhsldjk' at line 1"
The variables are passing correctly because they print out onto the screen. I feel like it's something silly I'm missing but I just don't see it.
Here's my code:
Code: Select all
<?php
session_start();
include 'db.php';
?>
<html>
<body>
<?php
$to = $_POST['to'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$from = $_SESSION['username'];
echo $to;
echo $from;
echo $subject;
echo $message;
mysql_query("INSERT INTO mail (to, from, subject, message)
VALUES('$to', '$from', '$subject', '$message')") or die (mysql_error());
?>
</body>
</html>