File: C:/xampp/htdocs/PBN/indexR.php
<?php
$gender='male';
if(count($_POST)>0) {
/* Form Required Field Validation */
foreach($_POST as $key=>$value) {
if(empty($_POST[$key])) {
$message = ucwords($key) . " field is required";
break;
}
}
/* Password Matching Validation */
if($_POST['password'] != $_POST['confirm_password']){
$message = 'Passwords should be same<br>';
}
/* Email Validation */
if(!isset($message)) {
if (!filter_var($_POST["userEmail"], FILTER_VALIDATE_EMAIL)) {
$message = "Invalid UserEmail";
}
}
/* Validation to check if gender is selected */
/* Validation to check if Terms and Conditions are accepted */
if(!isset($message)) {
if(!isset($_POST["terms"])) {
$message = "Accept Terms and conditions before submit";
}
}
if(!isset($message)) {
require_once("dbcontroller.php");
$db_handle = new DBController();
mysql_query("SET NAMES 'utf8'");
$query = "SELECT * FROM registered_users where email = '" . $_POST["userEmail"] . "'";
$count = $db_handle->numRows($query);
if($count==0) {
$query = "INSERT INTO registered_users (user_name, company, password, email) VALUES
('" . $_POST["userName"] . "', '" . $_POST["company"] . "', '" . md5($_POST["password"]) . "', '" . $_POST["userEmail"] . "')";
$current_id = $db_handle->insertQuery($query);
if(!empty($current_id)) {
$actual_link = "http://$_SERVER[HTTP_HOST]"."/PBN/activate.php?id=" . $current_id."&email=".$_POST["userEmail"]."&name=".$_POST["userName"];
//$toEmail = $_POST["userEmail"].",[email protected]";
//$toEmail = "[email protected]";
$toEmail = "[email protected],fred";
$subject = "PBN TOOL User Registration Activation Notification";
$content = "For PBN-Tool administrators, \r\n \r\nClick this link to activate ".$_POST['userName']."'s account. " . $actual_link ;
$mailHeaders = "From: [email protected]\r\n";
if(mail($toEmail, $subject, $content, $mailHeaders)) {
//$message = "You have registered and the activation mail is sent to your email. Click the activation link to activate you account.";
$message = "登錄成功,等候email啟動通知。You have registered and wait for the email notification";
}
unset($_POST);
} else {
$message = "Problem in registration. Try Again!";
}
} else {
$message = "User Email is already in use.";
}
}
}
?>
<html>
<head>
<title>PHP User Registration Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style.css" type="text/css" rel="stylesheet" />
</head>
<body>
<form name="frmRegistration" method="post" action="">
<table border="0" width="500" align="center" class="demo-table">
<?php if(isset($message)) { ?>
<div class="message"><?php echo $message; ?></div>
<?php } ?>
<tr>
<td>名稱 (account)</td>
<td><input type="text" class="demoInputBox" name="userName" value="<?php if(isset($_POST['userName'])) echo $_POST['userName']; ?>"></td>
</tr>
<tr>
<td>單位 (organization) </td>
<td><input type="text" class="demoInputBox" name="company" value="<?php if(isset($_POST['company'])) echo $_POST['company']; ?>"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" class="demoInputBox" name="password" value=""></td>
</tr>
<tr>
<td>Confirm Password</td>
<td><input type="password" class="demoInputBox" name="confirm_password" value=""></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" class="demoInputBox" name="userEmail" value="<?php if(isset($_POST['userEmail'])) echo $_POST['userEmail']; ?>"></td>
</tr>
<tr>
</tr>
<tr>
<td></td>
<td><input type="checkbox" name="terms"> <a href="./terms.htm">I accept Terms and Conditions</a></td>
</tr>
</table>
<div>
<input type="submit" name="submit" value="Register" class="btnRegister">
</div>
</form>
</body></html>