0

信息.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');
4

1 回答 1

0

根据 W3C 的定义,textarea没有value属性。相反,该值由<textarea></textarea>标签包装

<TEXTAREA name="thetext" rows="20" cols="80">
    First line of initial text.
    Second line of initial text.
</TEXTAREA>

这对于文档类型HTML5也有效

默认情况下, A<select>..</select>将始终提交第一个<option>。如果要预先选择另一个选项,则必须将属性添加selected="selected"到此选项。

http://www.w3.org/TR/html401/interact/forms.html#h-17.6.1

Select 没有类型属性。

示例:如何selected在 PHP 模板中添加属性

<select name="fieldname">
    <option value="on select,submitted value" <?php echo $myValue == 'on select,submitted value' ? ' selected="selected"' : ''; ?>>displayed value</option>
    <option value="on select,submitted value 2" <?php echo $myValue == 'on select,submitted value 2' ? ' selected="selected"' : ''; ?>>displayed value</option>
</select>
于 2013-01-13T11:35:06.620 回答