0

我有这个代码来保存文本区域的笔记

这是我的 post-note.php 文件

<?php
include('connect.php');
if(isset($_POST['note_title'])){
    $note_title = $_POST['note_title'];
    $note_description = $_POST['note_description'];
    $login_user_id = $_SESSION['user_id'];
    $errors = array();
    if($note_title == ""){
        $errors['note_title'] = 'fine';
    }else{
        $errors['note_title'] = 'fine';
    }
    if($note_description == ""){
        $errors['note_description'] = '<span class="note_description">Please enter something</span>';
    }elseif(strlen($note_description) < "3"){
        $errors['note_description'] = '<span class="note_description">your note is too short</span>';
    }else{
        $errors['note_description'] = 'fine';
    }
    if($errors['note_title'] && $errors['note_description'] == 'fine'){
        $Query = "INSERT INTO notes (note_title, login_user_id, note_description, is_private)
                                              VALUE('$note_title', '".$login_user_id."', '".$note_description."','0')";
        if (!mysql_query($Query)){
            die('Error: ' . mysql_error());
        }
        $errors['done'] = 'done';
        unset($_POST['note_title']);
        unset($_POST['note_description']);
    }
}
echo json_encode($errors);die;
?>`

我想第一次插入新行然后想更新数据库中的那一行

4

1 回答 1

0

在注释表中,添加一个列 ID(如果它不存在)。在创建笔记页面使用上面的代码。在 $_POST 中更新笔记页面传递该笔记的 id 字段。所以如果isset($_POST['id'])写一个UPDATE note ... WHERE id=$_POST['id']. 这将更新已创建的便笺,或者如果它是新便笺则插入。

在插入之前过滤用户输入

于 2013-10-10T05:36:14.883 回答