0

我有一个 MySQL 数据库,我通过使用 AJAX 的表单向其中添加记录。控制台告诉我,我的所有数据都已发布到 php 页面,并且我没有收到任何错误。但是,并非所有数据都显示在数据库中。

PHP:

    //set values sent from javascript
        $evaluator = $_SESSION['id'];
        $feedback = $_POST['feedback'];
        $student_work = $_POST['student_work'];
        $student = $_POST['student'];
        $assessment = $_POST['assessment'];
        $classwork = $_POST['classwork'];
        $best = $_POST['best'];
        $subject = $_POST['subject'];
        $binder = $_POST['binder'];
        $teacherid = $_POST['teacher'];
        $formid = $_POST['form'];
        $draft_flag = $_POST['s'];
        //set draft time to use for saving/updating drafts
        $draft_time = date("Y-m-d H:i:s");
        //flag that decided what we're saving, ie draft, submit, update.
        $flag =   $_POST['draft'];
        //Querys the database to get the form name
        $fquery = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT form_name FROM forms WHERE id_form='$formid' LIMIT 1");
        $row = mysqli_fetch_assoc($fquery);
        $form_name  = $row['form_name'];
        //query's the database to get the teacher's school for this evaluation
        $tquery = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT id_school FROM teachers WHERE teacher_id='$teacherid' LIMIT 1");
        $trow = mysqli_fetch_assoc($tquery);
        $id_school = $trow['id_school'];

        include_once 'functions/functions.php';

if ($draft_flag == "submit"){

//inserts collected data and sets status as submitted in the evaluations table
$query = "INSERT INTO evaluations SET 
        id_user = '$evaluator',
        time_submitted = LOCALTIME(),
        date_submitted = NOW(),
        feedback = '$feedback', 
        student_work_org = '$student_work',
        best_works_port = '$best',
        binder = '$binder',
        assesment_folders = '$assessment',
        classwork_organization = '$classwork',
        student_desks = '$student',
        subject_specific_rubric = '$subject',
        id_teacher = '$teacherid',
        id_school = '$id_school',
        id_form = '$formid',
        status = 'Submitted'";

mysqli_query($GLOBALS["___mysqli_ston"], $query); 
?>

在所有变量中,这些没有发布:

$feedback = $_POST['feedback'];
$student_work = $_POST['student_work'];
$student = $_POST['student'];
$assessment = $_POST['assessment'];
$classwork = $_POST['classwork'];
$best = $_POST['best']; 
$subject = $_POST['subject'];
$binder = $_POST['binder'];

那是 12 个没有发帖的 8 个。

编辑:这是js发送的内容:

ajax.send(
            "classwork=" + classwork
            + "&student_work=" + student_work
            + "&feedback=" + feedback
            + "&assessment=" + assessment
            + "&best=" + best
            + "&student=" + student
            + "&subject=" + subject
            + "&binder=" + binder
            + "&teacher=" + teacher
            + "&form=" + form
            + "&draft=" + draft
            + "&s=" + s
            );

我还有其他几种像这样工作正常的表格。在此先感谢您的帮助!

编辑:

请不要告诉我我的语法不正确,除非你要告诉我我漏掉了一个逗号什么的。(我检查过,所以我怀疑这是问题所在:))我知道这可能不是您插入的方式,但根据http://dev.mysql.com/doc/refman/5.7/en/它是正确的插入.html

刚试过,它做了同样的事情。

$query = "INSERT INTO evaluations (
        id_user, 
        time_submitted, 
        date_submitted, 
        feedback,  
        student_work_org, 
        best_works_port, 
        binder, '$binder',
        assesment_folders, 
        classwork_organization, 
        student_desks, 
        subject_specific_rubric, 
        id_teacher, 
        id_school, 
        id_form, 
        status) 
VALUES (
        '$evaluator',
        LOCALTIME(),
        NOW(),
        '$feedback',
        '$student_work',
        '$best',
        '$assessment',
        '$subject',
        '$classwork',
        '$student',
        '$teacherid',
        '$id_school',
        '$formid',
        'Submitted'
) ";
4

1 回答 1

1

您的INSERT 语法错误。这是正确的形式:

INSERT INTO <table name> (
    <field name foo>
    <field name bar>
    .
    .
    .
)
VALUES (
    <value for foo>,
    <value for bar>,
    .
    .
    .
)
于 2013-08-03T20:18:50.393 回答