Information.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>
Main problem is that it is not showing the value of the textarea and the select box which I manually updated through PHPmyadmin, but it shows the ones in the textboxs just fine.
UPDATE: The fields are now updating successfully! Even the text area and selectboxs are updated in the table. However, the value is not showing in the textarea or in the select box. So the problem still persists!
variable user_data:
$user_data = user_data($session_user_id,'user_id','username','password','first_name','last_name','email','gender','age','location','about_me');
As defined by the W3C, textarea does not have a
valueattribute. Instead, the value is wrapped by the<textarea></textarea>tagsThis is also valid for the document type HTML5
A
<select>..</select>will always submit the first<option>by default. If you want to preselect another option, you have to add the attributeselected="selected"to this option.http://www.w3.org/TR/html401/interact/forms.html#h-17.6.1
Select does not have a type attribute.
Example: how to add the
selectedattribute in a PHP template