Javascript是发布变量但我的所有数据都没有输入到数据库中

时间:2013-08-03 19:58:06

标签: php mysql mysql-5.7

我有一个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/insert.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'
) ";

1 个答案:

答案 0 :(得分:1)

您的INSERT syntax错了。这是正确的形式:

INSERT INTO <table name> (
    <field name foo>
    <field name bar>
    .
    .
    .
)
VALUES (
    <value for foo>,
    <value for bar>,
    .
    .
    .
)