Hi all, I am having a time with my coding. The codes for the form.php will add to the db if the action is giving as form.php. I am trying to get the page to redirect to the login.php. so I put the header function in. It redirects to the login.php as the header but does not add data to the db. So I tried to put the code login.php in the action for the form but it does not add to the db. Where can I put the redirect so it adds to data to the db and goes to the next page.???????
<?php
@include_once ("Connections/connect_to_mysql.php");
$err='';
if($_POST["submit"]){
// Validate form data
if($_POST["firstname"]=='') $err.='Please enter First Name<br>';
if($_POST["email"]=='') $err.='Please enter Email<br>';
if($err==''){
// Check if there are duplicate entries in the 'contacts' table
$results = mysql_query("SELECT id FROM `Members` WHERE firstname='".addslashes($_POST["firstname"])."' and Email='".addslashes($_POST["email"])."'");
if($row = mysql_fetch_array($results)){
$err.='Can not add duplicate entry<br>';
}
else{
// adding new record to 'contacts' table
mysql_query("INSERT INTO Members (firstname,lastname,country,Email)
values ('".addslashes($_POST["firstname"])."','".addslashes($_POST["lastname"])."','".addslashes($_POST["country"])."','".addslashes($_POST["email"])."')");
// redirecting to success screen
if($_POST['id']){
header("Location: login.php");
exit;
}
}
}
}
?>
<html>
<head>
<title>Add New Contact</title>
</head>
<body>
<h2>Register with us</h2>
<?php echo $err==''?'''<p style="color:red;">'.$err.'</p>') ?>
<form method="post" action="form.php">
<table border="0">
<tr>
<td valign="middle">First Name:</td>
<td><input type="text" name="firstname" size="30" value="<?php echo htmlspecialchars($firstname) ?>"></td>
</tr>
<tr>
<td valign="middle">Last Name:</td>
<td><input type="text" name="lastname" size="30" value="<?php echo htmlspecialchars($lastname) ?>"></td>
</tr>
<tr>
<td valign="middle">Country:</td>
<td><input type="text" name="country" size="30" value="<?php echo htmlspecialchars($country) ?>"></td>
</tr>
<tr>
<td valign="middle">Email:</td>
<td><input type="text" name="email" size="30" value="<?php echo htmlspecialchars($email) ?>"></td>
</tr>
</table><br>
<input type="submit" name="submit" value=" Submit! ">
</form>
</body>
</html>