form to database mysql problem
I am trying to set up a form to to send info to a database. I have set up my database called contact_form, with 2 fields name and email. I use awardspace.co.uk (free) but i cant seem get it to work. can someone look at both my form and PHP codes and see where i am going wrong. thanks
FORM CODE
<head>
<title>Formmail in DB</title>
</head>
<body>
<!-------------begin form------------>
<FORM ACTION="formindb.php" METHOD="POST" NAME="contact_form">
<TABLE>
<TR>
<TD><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Your Name:</font></TD>
<TD> <input type=text name="name"></TD>
</TR>
<TR>
<TD><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Email Address:</font></TD>
<TD><input type=text name="email"></TD>
</TR>
<TR>
<TD><input type="submit" value="Submit" name="Submit"></TD>
<TD><input type="reset" value="Reset" name="Reset"></TD>
</TR>
</TABLE>
</FORM>
<!-------------end form------------>
</body>
</html>
PHP CODE (mysql_connect("(database_name).mysql.aplus.net - i am not sure if this is correct if i want to connect to my awardspace mysql???)
$con = mysql_connect("(database_name).mysql.aplus.net","MYDatabaseUsername","MYDatabasePassword"); //Replace with your actual MySQL DB Username and Password
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("contact_form", $con); //Replace with your MySQL DB Name
$name=mysql_real_escape_string($_POST['name']); //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
$sql="INSERT INTO contact_form (name,email) VALUES ('$name','$email')"; /*form_data is the name of the MySQL table where the form data will be saved.
die('Error: ' . mysql_error());
}
echo "The form data was successfully added to your database.";
mysql_close($con);
?>
