我正在創建一個註冊表單,但我只有一個問題......爲什麼他們可以通過無效條目驗證?唯一的事情(我知道)是他們可以通過它而不選擇一個國家!使用PHP的表單無法正常工作
這裏是我的HTML/PHP代碼:
<table border="0" width="100%">
<form action="" method="post">
<tr><td><label>Username:<span class="requiredfield">*</span></label></td><td width="200"><input type="text" name="myusername" id="myusername" maxlength="15" style="background-color:transparent;" /></td></tr>
<tr><td><label>Summoner Name (League of Legends):<span class="requiredfield">*</span></label></td><td><input type="text" name="mysummonername" id="mysummonername" maxlength="30" /></td></tr>
<tr><td><label>Password:<span class="requiredfield">*</span></label></td><td><input type="password" name="mypassword" id="mypassword" maxlength="15" /></td></tr>
<tr><td><label>Retype Password:<span class="requiredfield">*</span></label></td><td><input type="password" name="myrpassword" id="myrpassword" maxlength="15" /></td></tr>
<tr><td><label>E-mail:<span class="requiredfield">*</span></label></td><td><input type="text" name="myemail" id="myemail" maxlength="65" /></td></tr>
<tr><td><label>Retype E-mail:<span class="requiredfield">*</span></label></td><td><input type="text" name="myremail" id="myremail" maxlength="65" /></td></tr>
<tr><td width="300"><br />Please note that we only need this information because we'll send out prices to the winners of our tournaments.</td></tr>
<tr><td><label>First Name:<span class="requiredfield">*</span></label></td><td><input type="text" name="myfname" id="myfname" maxlength="20" /></td></tr>
<tr><td><label>Last Name:<span class="requiredfield">*</span></label></td><td><input type="text" name="mylname" id="mylname" maxlength="30" /></td></tr>
<tr><td><label>Select Country:<span class="requiredfield">*</span></label></td><td><select name="mycountry" id="mycountry">
<option value="-choose-">-Choose-</option>
<option value="Afganistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
...
</select></td></tr>
<tr><td><label>Postal Code:</label></td><td><input type="text" name="myzipcode" id="myzipcode" maxlength="9" /></td></tr>
<tr><td><label>City:</label></td><td><input type="text" name="mycity" id="mycity" maxlength="60" /></td></tr>
<tr><td><label>Street:</label></td><td><input type="text" name="mystreet" id="mystreet" maxlength="50" /></td></tr>
<tr><td><label>Telephone Number:</label></td><td><input type="text" name="myphonenumber" id="myphonenumber" maxlength="15" /></td></tr>
<!--<tr><td><label>Invite Code<span style="color:#F00;">*</span>:</label></td><td><input type="text" name="myinvcode" id="myinvcode" /></td></tr>-->
<!-- <tr><td colspan="2" style="height: 20px;"></td></tr> -->
<tr><td width="300"><br />This information will be used later on when you have lost your password and need to retrieve it again.</td></tr>
<tr><td><label>Secret Question:<span class="requiredfield">*</span></label></td><td><input type="text" name="myscrtquestion" id="myscrtquestion" maxlength="50" /></td></tr>
<tr><td><label>Secret Answer:<span class="requiredfield">*</span></label></td><td><input type="text" name="myscrtanswer" id="myscrtanswer" maxlength="50" /></td></tr>
<tr><td></td><td><span class="button"><input type="submit" name="submitregister" value="Register" /></span></td></tr>
<tr><td colspan="2">By pressing "Register" you agree to the <a href='termsofuse.php'>terms of use</a> and our <a href='privacypolicy.php'>privacy policy</a>.</td></tr>
</form>
<?php
if (isset($_POST['submitregister'])) {
ob_start();
include 'config.php'; // Connect to Database
// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mysummonername=$_POST['mysummonername'];
$myfname=$_POST['myfname'];
$mylname=$_POST['mylname'];
$mypassword=$_POST['mypassword'];
$myrpassword=$_POST['myrpassword'];
$myemail=$_POST['myemail'];
$myremail=$_POST['myremail'];
// $myinvcode=$_POST['myinvcode'];
$myphonenumber=$_POST['myphonenumber'];
$mycountry=$_POST['mycountry'];
$myzipcode=$_POST['myzipcode'];
$mycity=$_POST['mycity'];
$mystreet=$_POST['mystreet'];
$myscrtquestion=$_POST['myscrtquestion'];
$myscrtanswer=$_POST['myscrtanswer'];
// check to make sure required fields are entered
if ($myusername == '' || $mysummonername == '' || $myfname == '' || $mylname == '' || $mypassword == '' || $myemail == '' || $mycountry == "-Choose-" || $myscrtquestion == '' || $myscrtanswer == '') {
echo "<span style='color:#F00;'>Please fill in all the required fields. All the fields which are marked with a <span style='color:#0076c9;'>*</span> are required fields!</span>";
爲什麼你仍然可以通過這個時候你沒有帶選擇一個國家?我無法弄清楚!
在未來,請的代碼只交相關位,而不是百線國家選擇下拉菜單中。 – jprofitt
請記住,PHP區分大小寫。 '選擇'是另一種東西,然後'選擇'作爲PHP中的變量。 – Dorvalla