php sql insert problem
Posted: Tue Aug 18, 2009 8:14 pm
I have a form which contains two input tags of type text and two textarea tags. They accept a name, contact info, problem and requirements. The following code is the form's action page.
Unfortunately my .mysql_error() code is saying "SQL 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 '@hotmail.com, computer crashes, use vb.net)' at line 1". I tried inputting an email address without the @ symbol to see if that was the only problem and it returned "SQL 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 'crashes, use vb.net)' at line 1"
The database is comprised of an int id column, two varchar columns for the name and contact info, two text columns for the problem and requirements, and a date column for the time it was processed.
I am using XAMPP's mysql and apache for this.
My two questions are these:
Am I not supposed to use a textarea tag inside of a form?
How do I handle the @ symbol inside of an insert?
Code: Select all
<?php
$name = $_POST['name'];
$contactinfo = $_POST['contactinfo'];
$problem = $_POST['problem'];
$requirements = $_POST['requirements'];
$connect = mysql_connect("localhost", "root", "");
mysql_select_db("elektrisolutionsdb", $connect);
$insert_query = "insert into workrequests(date,name,contactinfo,problem,requirements) VALUES(NOW(),$name, $contactinfo, $problem, $requirements)";
$sql = mysql_query($insert_query) or die("SQL ERROR: ".mysql_error());
if($sql) {
echo"<p>Thank you for submitting a work request form to Elektri.</p>";
}
else {
echo"<p>An error has occured. Your work request has not been processed.</p>";
}
?>
The database is comprised of an int id column, two varchar columns for the name and contact info, two text columns for the problem and requirements, and a date column for the time it was processed.
I am using XAMPP's mysql and apache for this.
My two questions are these:
Am I not supposed to use a textarea tag inside of a form?
How do I handle the @ symbol inside of an insert?