“字段列表”

时间:2017-03-07 01:19:35

标签: php mysql

所以我做了一个表格:

<div class="add">
    <div class="add_student">
    <h1>Add Student</h1>

    <form action="backend/func/add/add_student.php" method="post">
         <input type="text" name="student_id" placeholder="Student ID...">
         <input type="text" name="first_name" placeholder="First Name...">
         <input type="text" name="last_name" placeholder="Last Name...">

        <button type="submit" name="Add"><i class="fa fa-plus-circle fa-lg" aria-hidden="true"></i>Add</button>
   </form>
</div>

对于我输入123的第一个字段,对于第二个I输入测试,对于最后一个输入我输入test2。我收到一条错误消息:Unknown column 'test' in 'field list'。有人能帮助我吗?

我的PHP

<?php

// PROCESSES STUDENT INFO

// get connect page
require '../../connect.php';

// get input info
$student_id = $_POST['student_id'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];

// check if input is not empy
if(!empty($student_id) && !empty($first_name) && !empty($last_name)) {

    $result = mysqli_query($link, "INSERT INTO students (student_id, first_name, last_name)
    VALUES ($student_id, $first_name, $last_name);");

    if($result) {
        header("Location: ../../../admin.php?message=Success!");
    } else {
        echo mysqli_error($link);
        // header("Location: ../../../admin.php?message=Sorry we ran into an error");
    }
} else if (empty($student_id) || empty($first_name) || empty($last_name)) {
    header("Location: ../../../admin.php?message=Please add you're input values");
}

// header("Location: ../../../admin.php?message=Please add you're input values");
   ?>

1 个答案:

答案 0 :(得分:1)

你必须引用字符串字段:

 $result = mysqli_query($link, "INSERT INTO students (student_id, first_name, last_name)
    VALUES ($student_id, '$first_name', '$last_name');");