douhuan6305 2015-04-07 15:59
浏览 65
已采纳

从textarea发送数据到mysql

How can I get text area to post to my array and then be stored in the MySQL Database. Every element of the form works except for the "textarea" part Here is the code I have... Any help is appreciated! Thank You!!

<form action="" method="post">
    <ul>
        <li>
            First name*:<br>
            <input type="text" class="standard" name="first_name" value="<?php echo $user_data['first_name']; ?>">
        </li>
        <li>
            Last name:<br>
            <input class="standard" type="text" name="last_name" value="<?php echo $user_data['last_name']; ?>">
        </li>
        <li>
            Email*:<br>
            <input class="standard" type="text" name="email" value="<?php echo $user_data['email']; ?>">
        </li>
        <li>
            Phone Number:<br>
            <input class="standard" type="text" name="phone" value="<?php echo $user_data['phone']; ?>">
        </li>
        <li>
            About Me:<br>
            <textarea id="textarea" maxlength="1000" name="summary" value="<?php echo $user_data['summary']; ?>"></textarea>
            <div id="textarea_feedback"></div>
        </li>
        <li>
            Account type:<br>
            <select name="type">
                <option value="0" <?php if ($user_data['type'] == 0) echo "selected"; ?>>Employee</option>
                <option value="1" <?php if ($user_data['type'] == 1) echo "selected"; ?>>Employer</option>
            </select>
        </li>
        <li>
            <input type="submit" value="Update">
        </li>
    </ul>
</form>

So the "About Me" textarea is not working.

Here is the php sending it to the database:

<?php
if (isset($_GET['success']) === true && empty($_GET['success']) === true) {
echo 'Your details have been updated!';
} else {
if (empty($_POST) === false && empty($errors) === true) {

    $update_data = array(
        'first_name'    => $_POST['first_name'],
        'last_name'     => $_POST['last_name'],
        'email'         => $_POST['email'],
        'type'          => $_POST['type'],
        'phone'         => $_POST['phone'],
        'summary'       => $_POST['summary']
    );

    update_user($session_user_id, $update_data);
    header('Location: settings.php?success');
    exit();

} else if (empty($errors) === false) {
    echo output_errors($errors);
}
?>

Here is the function sending to database.

function user_data($user_id) {
$data = array();
$user_id = (int)$user_id;

$func_num_args = func_num_args();
$func_get_args = func_get_args();

if ($func_num_args > 1) {
    unset($func_get_args[0]);

    $fields = '`' . implode('`, `', $func_get_args) . '`';
    $data = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `user_id` LIKE $user_id"));

    return $data;
}
}
  • 写回答

2条回答 默认 最新

  • douliaotong4944 2015-04-07 16:12
    关注
    <textarea id="textarea" maxlength="1000" name="summary" value="<?php echo $user_data['summary']; ?>"></textarea>
    

    Change that line to:

    <textarea id="textarea" maxlength="1000" name="summary" ><?php echo $user_data['summary']; ?></textarea>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?