似たようなもの..しかし、あなたはアイデアを得る:
HTML コード :
<html>
<head>
<title>Registration </title>
</head>
<body>
<form name="reg_form" id="reg_form" method="post" action="confirm.php">
<table>
<tr><td colspan="2"><?php echo isset($_GET["msg"])?$_GET["msg"]:"";?> </td></tr>
<tr><td>Username</td><td><input type="text" name="username" id="username" /> </td></tr>
<tr><td>Password</td><td><input type="password" name="password" id="password" /> </td></tr>
<tr><td>confirm</td><td><input type="password" name="confirm" id="confirm" /> </td></tr>
<tr><td></td><td><input type="submit" name="btnsubmit" id="btnsubmit" /></td></tr>
</table>
</form>
</body>
</html>
フォーム送信時に実行されるPHP コード
<?php
$username=isset($_POST["username"])?$_POST["username"]:"";
$password=isset($_POST["password"])?$_POST["password"]:"";
$confirm=isset($_POST["confirm"])?$_POST["confirm"]:"";
if(!empty($username)&&!empty($password)){
if($password!=$confirm)
header("location:registration.php?msg=Password does not be match.");
$host="localhost";
$user="mysql_user_name";
$pass="mysql_password";
///open connection
$link=mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db("databse_name",$link);
$query="SELECT * FROM users WHERE username='".mysql_escape_string($username)."'";
$result=mysql_query($query);
//count no of rows
$count=mysql_num_rows($result);
if($count==1){
header("location:registration.php?msg=username already exists");
}else{
$qry="INSERT INTO users(username,password)VALUES('".mysql_escape_string($username)."'
,'".mysql_escape_string($password)."')";
mysql_query($qry);
//Sending mail part goes here
echo "You are successfully registered.";
}
mysql_close($link);
}else{
header("location:registration.php?msg=Username or password cannot be blank.");
}