信息.php
<?php
if (empty($_POST)===false){
$required_fields = array('first_name','last_name','gender','age','location','about_me');
foreach($_POST as $key =>$value){
if(empty($value) && in_array($key, $required_fields) === true){
$errors = 'fillin';
break 1;
}
}
}
if (empty($_POST)=== false && empty($errors) === true){
$update_data = array(
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'gender' => $_POST['gender'],
'age' => $_POST['age'],
'location' => $_POST['location'],
'about_me' => $_POST['about_me']
);
update_user($update_data);
echo 'updated';
}else if (empty($errors) === false){
echo $errors;
}
?>
<form action = "" method = "POST">
First Name: <input type = "text" name = "first_name" maxlength = "40" placeholder = "First Name" value = "<?php echo $user_data['first_name']; ?>"><br>
Last Name: <input type = "text" name = "last_name" maxlength = "40" placeholder = "Last Name" value = "<?php echo $user_data['last_name']; ?>"><br>
Gender: <select type = "text" name = "gender" value = "<?php echo $user_data['gender']; ?>"><option>Select</option><option name = "male" value = "Male">Male</option><option name = "female" value = "Female">Female</option><option name = "othergen" value = "Other">Other</option></select><br>
Age: <input type = "text" name = "age" maxlength = "3" placeholder = "What's your age?" value = "<?php echo $user_data['age']; ?>"><br>
Location: <input type = "text" name = "location" maxlength = "100" placeholder = "Your location?" value = "<?php echo $user_data['location']; ?>"><br>
About Me: <textarea type = "text" name = "about_me" maxlength = "500" placeholder = "Say something about yourself!" value = "<?php echo $user_data['about_me']; ?>"></textarea><br>
<input type = "submit" value = "submit">
</form>
主要问题是它没有显示文本区域的值和我通过 PHPmyadmin 手动更新的选择框,但它显示文本框中的值就好了。
更新:字段现在更新成功!甚至文本区域和选择框也在表格中更新。但是,该值未显示在文本区域或选择框中。所以问题依旧存在!
变量用户数据:
$user_data = user_data($session_user_id,'user_id','username','password','first_name','last_name','email','gender','age','location','about_me');