S
skinnypspplayer
Guest
I made a form in PHP to send data to a MySQL database but I'm getting this error:
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 ('', '', 'a', 'a')' at line 1
Here's the form page..
<?
ob_start ();
?>
<?
include("../session.php");
?>
<html>
<head>
<title>Send Message - KingPS3.com</title>
<link href="../style.css" rel="stylesheet" type="text/css" />
</head>
<body bgcolor="black">
<form action="mailpro.php" method="POST" name="SendMessage">
<p>
<input type="hidden" name="from" value="<?php echo "$session->username";?>"><br><br>
To:
<input type="text" size="15pt" name="to" value=""><br><br>
Subject:
<input type="text" size="15pt" name="subject" value=""><br><br>
Message:<br>
<textarea style="align: center" name="message" cols="38" rows="5" value=""></textarea><br><br></p>
<input value="Send" name="Submit" type="submit" /></form>
</body>
</html>
And then the page where form data is sent (to be put in a MYSQL database)..
<?php include('../session.php');?>
<?php
$con = mysql_connect("localhost","kingps3","**");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("kingps3", $con);
$from=mysql_real_escape_string($_POST['from']);
$to=mysql_real_escape_string($_POST['to']);
$subject=mysql_real_escape_string($_POST['subject']);
$message=mysql_real_escape_string($_POST['message']);
$sql="INSERT INTO mail (to,from,subject,message) VALUES ('$name', '$article', '$subject', '$message')";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
mysql_close($con);
header("Location: outbox.php");
?>
Any help? Immediate 10pts for best answer!
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 ('', '', 'a', 'a')' at line 1
Here's the form page..
<?
ob_start ();
?>
<?
include("../session.php");
?>
<html>
<head>
<title>Send Message - KingPS3.com</title>
<link href="../style.css" rel="stylesheet" type="text/css" />
</head>
<body bgcolor="black">
<form action="mailpro.php" method="POST" name="SendMessage">
<p>
<input type="hidden" name="from" value="<?php echo "$session->username";?>"><br><br>
To:
<input type="text" size="15pt" name="to" value=""><br><br>
Subject:
<input type="text" size="15pt" name="subject" value=""><br><br>
Message:<br>
<textarea style="align: center" name="message" cols="38" rows="5" value=""></textarea><br><br></p>
<input value="Send" name="Submit" type="submit" /></form>
</body>
</html>
And then the page where form data is sent (to be put in a MYSQL database)..
<?php include('../session.php');?>
<?php
$con = mysql_connect("localhost","kingps3","**");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("kingps3", $con);
$from=mysql_real_escape_string($_POST['from']);
$to=mysql_real_escape_string($_POST['to']);
$subject=mysql_real_escape_string($_POST['subject']);
$message=mysql_real_escape_string($_POST['message']);
$sql="INSERT INTO mail (to,from,subject,message) VALUES ('$name', '$article', '$subject', '$message')";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
mysql_close($con);
header("Location: outbox.php");
?>
Any help? Immediate 10pts for best answer!