HTML选项表单与php


HTML option form with php

目前我对PHP和HTML有点困,我的老师让我把我的代码改成下拉选择,

到目前为止我有这个

$html .='<option value="Argentina" <?php if($_POST['YourCountry']=="Argentina") echo "selected=selected"; ?>>Argentina</option>';

我不知道为什么它不工作。我试图得到它,以便当一个人选择框中的选项,它将值设置到插入查询。这是我的输入项,我的老师让我把它改成选项1,我不知道选项1怎么了

$html .='<input type="text" name="userCountry" id="userCountry" value="'.htmlentities(stripcslashes($_POST['userCountry'])).'" /><br/>'."'n";

完整代码 ===================================>

<?php
class HomeView extends View {
    protected function displayContent() {
        $html .= '<div id="pageinfo">'."'n";
        $html .= '<h2>'.$this -> pageInfo['pageHeading'].'</h2>'."'n";
        $html .= '</div>'."'n";
            if($_POST['register'] == "Submit") {
            //validate the form

            $vresult = $this -> model -> validateRegisterUser();

            //Check ALL okay
                 if ($vresult['ok'] == true) {
                //Call database

                            if ($this -> model -> register()) {
                                $htmt .='<div id="space">'."'n";
                                $html .='<div id="userreg">'."'n";
                                $html .='<p> User registered successfully<p>'."'n";
                                $html .= '<p>Please login '.$_POST['userName'].'</p>'."'n";
                                $html .='<img src ="optimized/images/joined.jpg" alt="welcome new member"/>'."'n";
                                $html .='</div>'."'n";
                                $html .='</div>'."'n";
                                    } else {
                                $html .='<div id="space">'."'n";
                                $html .='<img src ="optimized/images/failed.jpg" alt="failed to create new member"/>'."'n";
                                $html .= '<p> User creation failed. Please try again <p>'."'n";
                                $html .='</div>'."'n";
                            }        
                        return $html;
                }   
            }
            $html .='<div id="register">'."'n";
                $html .='<img src="optimized/images/rg.jpg" alt="registerimage"/>'."'n";
                $html .='<form method="post" action="'.$_SERVER['REQUEST_URI'].'" onSubmit="return confirm("Are you sure?");">'."'n";
                    $html .='<fieldset>'."'n";
                        $html .='<legend>'.'New Members Form'.'</legend>'."'n";
                        $html .='<label for="username">Username: </label><br/>'."'n";
                        $html .='<input type="text" name="userName" id="userName" value="'.htmlentities(stripcslashes($_POST['userName'])).'" /><br/>'."'n";
                        $html .='<div class="error">'.$vresult['userNameMsg'].'</div>'."'n";
                        $html .='<label for="userFName">Firstname: </label><br/>'."'n";
                        $html .='<input type="text" name="userFName" id="userFName1" value="'.htmlentities(stripcslashes($_POST['userFName'])).'" /><br/>'."'n";
                        $html .='<div class="error">'.$vresult['userFNameMsg'].'</div>'."'n";
                        $html .='<label for="userLName">Surname: </label><br/>'."'n";
                        $html .='<input type="text" name="userLName" id="userLName" value="'.htmlentities(stripcslashes($_POST['userLName'])).'" /><br/>'."'n";
                        $html .='<div class="error">'.$vresult['userLNameMsg'].'</div>'."'n";
                        $html .='<label for="userEmail">Email: </label><br/>'."'n";
                        $html .='<input type="text" name="userEmail" id="userEmail" value="'.htmlentities(stripcslashes($_POST['userEmail'])).'" /><br/>'."'n";
                        $html .='<div class="error">'.$vresult['userEmailMsg'].'</div>'."'n";
                        $html .='<label for="userPassword">Password: </label><br/>'."'n";
                        $html .='<input type="password" name="userPassword" id="userPassword1" value="'.htmlentities(stripcslashes($_POST['userPassword'])).'" /><br/>'."'n";
                        $html .='<div class="error">'.$vresult['userPasswordMsg'].'</div>'."'n";
                        $html .='<label for="userPassword">Re-Enter Password: </label><br/>'."'n";
                        $html .='<input type="password" name="userPassword2" id="userPassword2" value="'.htmlentities(stripcslashes($_POST['userPassword2'])).'" /><br/>'."'n";
                        $html .='<div class="error">'.$vresult['userPrematchPass'].'</div>'."'n";

                        $html .='<label for="userPhone">Telephone: </label><br/>'."'n";
                        $html .='<input type="text" name="userPhone" id="userPhone" value="'.htmlentities(stripcslashes($_POST['userPhone'])).'" /><br/>'."'n";
                        $html .='<div class="error">'.$vresult['userPhoneMsg'].'</div>'."'n";
                        $html .='<label for="userAddress">Address: </label><br/>'."'n";
                        $html .='<input type="text" name="userAddress" id="userAddress" value="'.htmlentities(stripcslashes($_POST['userAddress'])).'" /><br/>'."'n";
                        $html .='<div class="error">'.$vresult['userAddressMsg'].'</div>'."'n";
                        $html .='<label for="userCity">City: </label><br/>'."'n";
                        $html .='<input type="text" name="userCity" id="userCity" value="'.htmlentities(stripcslashes($_POST['userCity'])).'" /><br/>'."'n";
                        $html .='<div class="error">'.$vresult['userCityMsg'].'</div>'."'n";
                        $html .='<label for="userCountry">NewZealand: </label><br/>'."'n";
                         $html .='<select name="Location">'."'n";
$html .='<option value=""></option>'."'n";
$html .='<option value="North-Island">North-Island</option>';
$html .='<option value="South-Island">South-Island</option>';
$html .='<option value="Other">Other</option>';
 $html .='<option value="Argentina" <?php if($_POST['YourCountry']=="Argentina") echo "selected=selected"; ?>>Argentina</option>';




                        $html .='<input type="text" name="userCountry" id="userCountry" value="'.htmlentities(stripcslashes($_POST['userCountry'])).'" /><br/>'."'n";
                        $html .='<div class="error">'.$vresult['userCountryMsg'].'</div>'."'n";
                        $html .='<label for="userPostcode">Post Code: </label><br/>'."'n";
                        $html .='<input type="text" name="userPostcode" id="userPostcode" value="'.htmlentities(stripcslashes($_POST['userPostcode'])).'" /><br/>'."'n";
                        $html .='<div class="error">'.$vresult['userPostcodeMsg'].'</div>'."'n";
                        $html .='<input type="submit" name="register" value="Submit" id="submit"/>'."'n";
                    $html .='</fieldset>'."'n";
                $html .='</form>'."'n";
            $html .=' </div>'."'n";
        return $html;
    }
}
?>

ADD

</select>

添加
<?php if($_POST['YourCountry']=="XXXXX") echo "selected=selected"; ?>

在其他选项标签

改变
<select name="Location"> to  <select name="YourCountry">
* *

action="'.$_SERVER['REQUEST_URI'].'"  is not good for Xss