我已经在php中创建了一个用户配置文件页面。用户插入性别和电话号码,所有这些都存储在数据库中的一个称为配置文件的表中。我的问题是,如何让下拉列表保持用户以前输入的选定值。例如,如果用户选择男性,则下拉列表应将男性保留为选定的选项,并且仅当用户决定再次更改时才更改。下拉列表保持选定的最后一个值输入php
下面是代码:
<form action="" method="POST" >
<?php
if (isset($_GET['success']) === true && empty($_GET['success'])===true){
echo'Profile Updated Sucessfuly';
}else{
if(empty($_POST) === false && empty($errors) === true){
$update_data_profile = array('gender' => $_POST['gender'],
'telephone' => $_POST['telephone']);
update_user_profile($session_user_id, $update_data_profile);
header('Location: profile_update.php?success');
exit();
}else if (empty($errors) === false){
echo output_errors($errors);
}
?>
Gender<select name="gender" id="gender">
<option value=" "> EMPTY </option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
Telephone <input name="telephone" type="text" size="25" />
<input type="submit" value="" name="submit"/></br>
这是我用在数据库中插入数据的功能:
function update_user_profile($user_id, $update_data_profile){
$result = mysql_query("select user_id from profile where user_id = $user_id limit 1");
$user_id = $update_data_profile['user_id'] ;
if(count($update_data_profile)){
$columns = array();
$values = array();
foreach($update_data_profile as $field => $data){
$columns[] = $field;
$values[] = $data;
}
}
mysql_query(" INSERT INTO `profile` (" . implode(",", $columns) .") values ('" . implode("','", $values) . "')") or die (mysql_error());
[你有什么试过](http://whathaveyoutried.com)?是的,你给我们提供了你已经完成的代码,但你试图完成你的问题的是什么?提示:[选择HTML选项](http://www.w3schools.com/tags/att_option_selected.asp) – UnholyRanger 2013-02-28 17:03:07
什么都还不知道如何 – 33528 2013-02-28 17:09:58
为什么不把这些张贴值存储在用户会话或cookie中,以及如果他们是目前,默认值的格式为 – Waygood 2013-02-28 17:13:50