从textarea发送数据到mysql

时间:2015-04-07 15:59:35

标签: php mysql

如何将文本区域发布到我的阵列,然后存储在MySQL数据库中。除了“textarea”部分之外,表单的每个元素都有效。这是我的代码...任何帮助表示赞赏!谢谢!!

<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>

所以“关于我”textarea不起作用。

这是php将其发送到数据库:

<?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);
}
?>

这是发送到数据库的功能。

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 个答案:

答案 0 :(得分:1)

textarea的name属性似乎有拼写错误。你写了名字 - “摘要”而不是名字=“摘要”。

答案 1 :(得分:1)

<textarea id="textarea" maxlength="1000" name="summary" value="<?php echo $user_data['summary']; ?>"></textarea>

将该行更改为:

<textarea id="textarea" maxlength="1000" name="summary" ><?php echo $user_data['summary']; ?></textarea>