I am trying to submit contents of a valid PHP form to my MYSQL database!
the database is called 'customer'. I am using wamp to show my php page
Please help me! i have spent hours looking around on Google and Php.net to no avail
<html>
<head>
<title>PHP Data Entery</title>
</head>
<body>
<form action="" method="post">
<B>Name: </B><input type="text" name="Name"/><br><br>
<B>Address: </B><input type="text" name="Address"/><br><br>
<B>Postcode: </B><input type="text" name="Postcode"/><br><br>
<B>Telephone: </B><input type="text" name="Telephone"/<br><br><br>
<B>Email: </B><input type="text" name="Email"/><br><br>
<input type="submit" name="submit" id="submit" value="submit" />
</form>
<?php if ((strlen($_POST['Name'])<=50) && ctype_alpha($_POST['Name'])){
$Name=$_POST['Name'];}
else {$Name=invalid;}
if (strlen($_POST['Address'])<=200){
$Address= $_POST['Address'];}
else {$Address=invalid;}
if (strlen($_POST['Postcode'])<=10){
$Postcode=$_POST['Postcode'];}
else {$Postcode=invalid;}
if ((strlen($_POST['Telephone'])<=15)&&(!preg_match("/[^\d]/m", $_POST['Telephone']))) {
$Telephone=$_POST['Telephone'];}
else {$Telephone=invalid;}
if ((eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['Email']))&&(strlen($POST_['Email'])<=100)){
$Email=$_POST['Email'];}
else {$Email=invalid;}
if ($Name!='invalid' && $Address!='invalid' && $Postcode!='invalid' && $Telephone!='invalid' && $Email!='invalid'){
$Form=valid;}
else {$Form=invalid;}
if ($Form =='valid'){
$con = mysql_connect("localhost","ian","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("customer", $con);
$result = mysql_query($query);
$query=("INSERT INTO customer SET (Name , Address, Postcode, Telephone, Email) Values ('$Name', '$Address', '$Postcode', '$Telephone', '$Email')");
echo "the form has been submitted";
mysql_close($con);}
else echo "The form was invalid and not submitted";
?>
<BR>
<BR>
<BR>
Form: <?php echo $Form; ?>
<BR>
</body>
</html>

New Topic/Question
Reply



MultiQuote




|