私はphpとmysqlで登録フォームを作成していますが、必要なファイルが空かどうかを確認したいのですが、問題は、ユーザー名が空の場合にエラーメッセージのみが表示され、他のエラーメッセージが表示されないことです。この問題で??
register.php
<!--<?php require_once('for members/scripts/global.php');?>-->
<?php
$message = "";
if(isset($_POST['username'])){
$username = $_POST['username'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
$bdate = $_POST['birthdate'];
$phone = $_POST['phonenumber'];
$country = $_POST['country'];
$local_adress = $_POST['adress'];
@$specialization = $_POST['specialisation'];
//error handeling
if((!$username)||(!$fname)||(!$lname)||(!$email)||(!$pass1)||(!$pass2)||(!$bdate)||(!$phone)||(!$country)||(!$local_adress)||(!$specialization)){
$message = "please insert all fields below";
if($username == "")
{
$message = "Enter User Name";
}
if($fname = "")
{
$message = "Enter First name";
}
if($email = "")
{
$message = "Enter Email Adress";
}
if($pass1 = "")
{
$message = "Enter password";
}
if($pass2 = "")
{
$message = "rechek the password ";
}
}
else if($pass1!=$pass2){
$message = "your password do not match!";
}else{
//securing the data
$username = preg_replace("#[^0-9a-z]#i","",$username);
$fname = preg_replace("#[^0-9a-z]#i","",$fname);
$lname = preg_replace("#[^0-9a-z]#i","",$lname);
$pass1 = sha1($pass1);
$email = mysql_real_escape_string($email);
// checking for duplicate
$user_query = mysql_query("SELECT username FROM members WHERE username = '$username'LIMIT 1") or die("could not check the username");
$count_username = mysql_num_rows($user_query);
$email_query = mysql_query("SELECT email FROM members WHERE email = '$email'LIMIT 1") or die("could not check the username");
$count_email = mysql_num_rows($email_query);
if($count_username > 0){
$message = " your username is alredy in use";
}elseif($count_email > 0){
$message = "your email is alredy in use";
}else{
// insert the members
$ip_adress = $_SERVER['REMOTE_ADDR'];
$query = mysql_query("INSERT INTO members(username, firstname, lastname, email, password, ip_adress, sign_up_date)VALUES('$username', '$fname', '$lname', '$email', '$pass1', '$ip_adress', now())")or die("could not insert data");
$member_id = mysql_insert_id();
mkdir("users/$member_id",0755);
$message = "you have now been registered";
header("Location: home.php");
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Register Page</title>
<link href="style/stylesheet.css"rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="visitorHeader">
<img src="web_header copy.jpg" alt="visitor header" />
</div>
<div class="container center">
<p><?php print("$message")?></p>
<table width="280" border="1" align="center">
<form action="register.php" method="post">
<tr>
<td><label for="username"><span class="Fields">User Name</span> <span class="requiredField">*</span></label></td>
<td>
<input type="text" name="username" placeholder="Username" /><br /></td>
</tr>
<tr>
<td><label for="firstname"><span class="Fields">First Name</span> <span class="requiredField">*</span></label></td>
<td>
<input type="text" name="fname" placeholder="Firstname" /><br /></td>
</tr>
<tr>
<td><label for="lasttname" class="Fields">Last Name</label></td>
<td>
<input type="text" name="lname" placeholder="Lastname" /><br /></td>
</tr>
<tr>
<td><label for="birthdate" class="Fields">Birth Date</label></td>
<td>
<input type="date" name="birthdate" value= "YYYY_MM_DD" onfocus="if (this.value == 'YYYY_MM_DD') {this.value = '';}" onblur="if (this.value == '') {this.value = 'YYYY_MM_DD';}" /><br /></td>
</tr>
<tr>
<td class="Fields"><label for="phonenumber">Phone Number</label>
<td>
<input type="tel" name="phonenumber" value="000-0-000 000" onfocus="if (this.value == '000-0-000 000') {this.value = '';}" onblur="if (this.value == '') {this.value = '000-0-000 000';}" /></td>
</tr>
<tr>
<td class="Fields"><label for="country">Country</label></td>
<td>
<select name="country" id="country"><option selected=>please choose coutry<option>lebanon<option>Us<option>europe
</select></td>
</tr>
<tr>
<td class="Fields"><label for="adress">Local Adress <span class="requiredField">*</span></label></td>
<td>
<input type="text" name="adress" placeholder="adress" /></td>
</tr>
<tr>
<td class="Fields"><label for="specialisation">Specialisation <span class="requiredField">*</span></label></td>
<td>
<select name="specialisation" id="specialisation">
</select></td>
</tr>
<tr>
<td class="Fields"><label for="email">Email Adress<span class="requiredField">*</span></label></td>
<td>
<input type="text" name="email" placeholder="Email Adress" /><br /></td>
</tr>
<tr>
<td class="Fields"><label for="password">Password<span class="requiredField">*</span></label></td>
<td>
<input type="password" name="pass1" placeholder="Password" /><br /></td>
</tr>
<tr>
<td class="Fields"><label for="password2">Re_Password<span class="requiredField">*</span></label></td>
<td>
<input type="password" name="pass2" placeholder="Validate Password" /><br /></td>
</tr>
<tr>
<td>
<input type="submit" value="Register"/>
</td>
</tr>
</form>
</table>
</div>
</body>
</html>