information.php文件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>
主要問題在表中選擇框和文本區在MySQL中值是,它沒有顯示textarea的價值,這是我手動更新選擇框通過PHPmyadmin,但它顯示在文本框中的很好。
更新:字段現在更新成功!即使文本區域和選擇框在表格中更新。但是,該值未顯示在textarea或選擇框中。所以問題仍然存在!
可變的user_data:
$user_data = user_data($session_user_id,'user_id','username','password','first_name','last_name','email','gender','age','location','about_me');
請不要使用'mysql_ *'函數編寫新代碼。他們不再被維護,社區已經開始[棄用流程](http://goo.gl/q0gwD)。看到[紅色框](http://goo.gl/OWwr2)?相反,您應該瞭解[準備好的語句](http://goo.gl/orrj0)並使用[PDO](http://goo.gl/TD3xh)或[MySQLi](http://php.net/ mysqli的)。如果你不能決定哪些,[這篇文章](http://goo.gl/YXyWL)會幫助你。如果你選擇PDO,[這裏是很好的教程](http://goo.gl/b2ATO)。另請參閱[爲什麼不應該在PHP中使用mysql函數?](http://goo.gl/J5jAo) – DCoder
性別:
在你提供的代碼中,實際上並沒有在任何地方調用函數update_user(),所以我並不感到驚訝,表沒有更新 – Pankrates