Hi guys,
Im trying to create a form that when filled out will post all its information to a mysql database.
Everytime i try to fill in the form to test it, it keeps throwing back this error message:
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 'a')' at line 1
I cant seem to understand it, i think i have entered all the correct information but i am not sure.
Here is the code from the page where the form sits. (Named - waiting_list.php)
<td width="653"><FORM ACTION="waiting_list_return.php" METHOD="POST" onSubmit="submitonce(this)" NAME="contact_form">
<TABLE align="center">
<TR>
<TD width="190" class="body_text_black"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">First Name</font></TD>
<TD width="242" class="body_text_black"> <input type=text name="fname" onkeypress="return handleEnter(this, event)"></TD>
</TR>
<TR>
<TD width="190" class="body_text_black"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Last Name:</font></TD>
<TD width="242" class="body_text_black"> <input type=text name="lname" onkeypress="return handleEnter(this, event)"></TD>
</TR>
<TR>
<TD width="190" class="body_text_black"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Address:</font></TD>
<TD width="242" class="body_text_black"> <input type=text name="address" onkeypress="return handleEnter(this, event)"></TD>
</TR>
<TR>
<TD width="190" class="body_text_black"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Postcode:</font></TD>
<TD width="242" class="body_text_black"> <input type=text name="postcode" onkeypress="return handleEnter(this, event)"></TD>
</TR>
<TR>
<TD width="190" class="body_text_black"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Date of Birth:</font></TD>
<TD width="242" class="body_text_black"> <input type=text name="dob" onkeypress="return handleEnter(this, event)"></TD>
</TR>
<TR>
<TD width="190" class="body_text_black"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Email Address:</font></TD>
<TD width="242" class="body_text_black"> <input type=text name="email" onkeypress="return handleEnter(this, event)"></TD>
</TR>
<TR>
<TD width="190" height="136" class="body_text_black"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Additional Information:</font></TD>
<TD width="242" class="body_text_black"> <textarea name="addinfo" rows="8" onkeypress="return handleEnter(this, event)"></textarea>
<a href="#" class="hintanchor" onMouseover="showhint('If you have any additional information you would like us to know please fill it in here.', this, event, '150px')">[?]</a></TD>
</TR>
<TR>
<TD width="190" class="body_text_black"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Official Membership Number:</font></TD>
<TD width="242" class="body_text_black"> <input type=text name="mnumber" onkeypress="return handleEnter(this, event)"><a href="#" class="hintanchor" onMouseover="showhint('This number can be found on your official Liverpool FC Membership card. This DOES NOT influence your eligibility when joing PLFSC.', this, event, '150px')">[?]</a></TD>
</TR>
<TD colspan="2" class="body_text_black"><div align="center">
<input type="submit" value="Submit" name="Submit">
<input type="reset" value="Reset" name="Reset">
</div></TD>
</TR>
</TABLE>
</FORM> </td>
and then this is the actual php code (Named waiting_list_return.php)
<?php
$con = mysql_connect("mysql15.streamline.net","qqqqqqqqq","qqqqqqqqqqq"); //Replace with your actual MySQL DB Username and Password
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("plfsccou2", $con); //Replace with your MySQL DB Name
$fname=mysql_real_escape_string($_POST['fname']); //This value has to be the same as in the HTML form file
$lname=mysql_real_escape_string($_POST['lname']); //This value has to be the same as in the HTML form file
$address=mysql_real_escape_string($_POST['address']); //This value has to be the same as in the HTML form file
$postcode=mysql_real_escape_string($_POST['postcode']); //This value has to be the same as in the HTML form file
$dob=mysql_real_escape_string($_POST['dob']); //This value has to be the same as in the HTML form file
$email=mysql_real_escape_string($_POST['email']); //This value has to be the same as in the HTML form file
$addinfo=mysql_real_escape_string($_POST['addinfo']); //This value has to be the same as in the HTML form file
$mnumber=mysql_real_escape_string($_POST['mnumber']); //This value has to be the same as in the HTML form file
$sql="INSERT INTO wlist (fname,lname,address,postcode,dob,email,addinfo,mnumber) VALUES ('$fname','$lname','$address','$postcode','$dob','email','$addinfo','$lname'$mnumber')"; /*form_data is the name of the MySQL table where the form data will be saved.
name and email are the respective table fields*/
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
echo "The form data was successfully added to your database.";
mysql_close($con);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
any ideas???
Im trying to create a form that when filled out will post all its information to a mysql database.
Everytime i try to fill in the form to test it, it keeps throwing back this error message:
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 'a')' at line 1
I cant seem to understand it, i think i have entered all the correct information but i am not sure.
Here is the code from the page where the form sits. (Named - waiting_list.php)
<td width="653"><FORM ACTION="waiting_list_return.php" METHOD="POST" onSubmit="submitonce(this)" NAME="contact_form">
<TABLE align="center">
<TR>
<TD width="190" class="body_text_black"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">First Name</font></TD>
<TD width="242" class="body_text_black"> <input type=text name="fname" onkeypress="return handleEnter(this, event)"></TD>
</TR>
<TR>
<TD width="190" class="body_text_black"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Last Name:</font></TD>
<TD width="242" class="body_text_black"> <input type=text name="lname" onkeypress="return handleEnter(this, event)"></TD>
</TR>
<TR>
<TD width="190" class="body_text_black"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Address:</font></TD>
<TD width="242" class="body_text_black"> <input type=text name="address" onkeypress="return handleEnter(this, event)"></TD>
</TR>
<TR>
<TD width="190" class="body_text_black"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Postcode:</font></TD>
<TD width="242" class="body_text_black"> <input type=text name="postcode" onkeypress="return handleEnter(this, event)"></TD>
</TR>
<TR>
<TD width="190" class="body_text_black"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Date of Birth:</font></TD>
<TD width="242" class="body_text_black"> <input type=text name="dob" onkeypress="return handleEnter(this, event)"></TD>
</TR>
<TR>
<TD width="190" class="body_text_black"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Email Address:</font></TD>
<TD width="242" class="body_text_black"> <input type=text name="email" onkeypress="return handleEnter(this, event)"></TD>
</TR>
<TR>
<TD width="190" height="136" class="body_text_black"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Additional Information:</font></TD>
<TD width="242" class="body_text_black"> <textarea name="addinfo" rows="8" onkeypress="return handleEnter(this, event)"></textarea>
<a href="#" class="hintanchor" onMouseover="showhint('If you have any additional information you would like us to know please fill it in here.', this, event, '150px')">[?]</a></TD>
</TR>
<TR>
<TD width="190" class="body_text_black"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Official Membership Number:</font></TD>
<TD width="242" class="body_text_black"> <input type=text name="mnumber" onkeypress="return handleEnter(this, event)"><a href="#" class="hintanchor" onMouseover="showhint('This number can be found on your official Liverpool FC Membership card. This DOES NOT influence your eligibility when joing PLFSC.', this, event, '150px')">[?]</a></TD>
</TR>
<TD colspan="2" class="body_text_black"><div align="center">
<input type="submit" value="Submit" name="Submit">
<input type="reset" value="Reset" name="Reset">
</div></TD>
</TR>
</TABLE>
</FORM> </td>
and then this is the actual php code (Named waiting_list_return.php)
<?php
$con = mysql_connect("mysql15.streamline.net","qqqqqqqqq","qqqqqqqqqqq"); //Replace with your actual MySQL DB Username and Password
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("plfsccou2", $con); //Replace with your MySQL DB Name
$fname=mysql_real_escape_string($_POST['fname']); //This value has to be the same as in the HTML form file
$lname=mysql_real_escape_string($_POST['lname']); //This value has to be the same as in the HTML form file
$address=mysql_real_escape_string($_POST['address']); //This value has to be the same as in the HTML form file
$postcode=mysql_real_escape_string($_POST['postcode']); //This value has to be the same as in the HTML form file
$dob=mysql_real_escape_string($_POST['dob']); //This value has to be the same as in the HTML form file
$email=mysql_real_escape_string($_POST['email']); //This value has to be the same as in the HTML form file
$addinfo=mysql_real_escape_string($_POST['addinfo']); //This value has to be the same as in the HTML form file
$mnumber=mysql_real_escape_string($_POST['mnumber']); //This value has to be the same as in the HTML form file
$sql="INSERT INTO wlist (fname,lname,address,postcode,dob,email,addinfo,mnumber) VALUES ('$fname','$lname','$address','$postcode','$dob','email','$addinfo','$lname'$mnumber')"; /*form_data is the name of the MySQL table where the form data will be saved.
name and email are the respective table fields*/
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
echo "The form data was successfully added to your database.";
mysql_close($con);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
any ideas???
Last edited: