duanguochong0397 2016-05-21 07:49
浏览 11

我的INSERT INTO不能在PHP页面中工作,而是在SQL中工作

i have here a page for the registering a crew but i dont know what seems to be the problem. the query is working in phpmyadmin but not working in php page. here is my code:

    session_start();
    require 'config.php';

    if (@$_SESSION['username']) {

    if (isset($_POST['first_name'])&&isset($_POST['middle_name'])&&isset($_POST['last_name'])&&isset($_POST['age'])&&isset($_POST['birth_date'])&&isset($_POST['birth_place'])&&isset($_POST['gender'])&&isset($_POST['martial_status'])&&isset($_POST['religion'])&&isset($_POST['nationality'])&&isset($_POST['email'])&&isset($_POST['address1'])&&isset($_POST['address2'])&&isset($_POST['course'])&&isset($_POST['school'])&&isset($_POST['remarks'])) {

        $first_name = $_POST['first_name'];
        $middle_name = $_POST['middle_name'];
        $last_name = $_POST['last_name'];
        $age = $_POST['age'];
        $birth_date = $_POST['birth_date'];
        $birth_place =$_POST['birth_place'];
        $gender = $_POST['gender'];
        $martial_status = $_POST['martial_status'];
        $religion = $_POST['religion'];
        $nationality = $_POST['nationality'];
        $email = $_POST['email'];
        $address1 = $_POST['address1'];
        $address2 = $_POST['address2'];
        $course = $_POST['course'];
        $school = $_POST['school'];
        $remarks = $_POST['remarks'];
        $date_added = date('Y-m-d');



            if (!empty($first_name)&&!empty($middle_name)&&!empty($last_name)&&!empty($age)&&!empty($birth_date)&&!empty($birth_place)&&!empty($gender)&&!empty($martial_status)&&!empty($religion)&&!empty($nationality)&&!empty($email)&&!empty($address1)&&!empty($course)&&!empty($school)) {


                    $query = "INSERT INTO `crew_info` (first_name,middle_name,last_name,age,birth_date,birth_place,gender,martial_status,religion,nationality,email_address,address_1,address_2,course,school_graduated,remarks,date_added,crew_status) VALUES ('$first_name','$middle_name','$last_name','$age','$birth_date','$birth_place','$gender','$martial_status','$religion','$nationality','$email','$address1','$address2','$course','$school','$remarks','$date_added','PENDING')";

                    echo 'Crew Successfuly Send to "PENDING PAGE"';

            }
            else {
                echo 'Some field is empty';
            }
    }


    echo '<!DOCTYPE html>
<html>
<head>
    <title>Add New Crew</title>
</head>
<body>

    <form action="add_crew.php" method="POST">
    <table>
        <tr>
            <td>
                First Name: 
            </td>
            <td>
                <input type="text" name="first_name" ></input>
            </td>
        </tr>
        <tr>
            <td>
                Middle Name: 
            </td>
            <td>
                <input type="text" name="middle_name" ></input>
            </td>
        </tr>
        <tr>
            <td>
                Last Name: 
            </td>
            <td>
                <input type="text" name="last_name" ></input>
            </td>
        </tr>
    </table><br>
    <table>
        <tr>
            <td>
                Age: 
            </td>
            <td>
                <input type="text" name="age" ></input>
            </td>
        </tr>
        <tr>
            <td>
                Birth Date: 
            </td>
            <td>
                <input type="text" name="birth_date" ></input>
            </td>
        </tr>
        <tr>
            <td>
                Birth Place: 
            </td>
            <td>
                <input type="text" name="birth_place" ></input>
            </td>
        </tr>
    </table><br>
    <table>
        <tr>
            <td>
                Gender: 
            </td>
            <td>
                <input type="text" name="gender" ></input>
            </td>
        </tr>
        <tr>
            <td>
                Martial Status: 
            </td>
            <td>
                <input type="text" name="martial_status" ></input>
            </td>
        </tr>
        <tr>
            <td>
                Religion: 
            </td>
            <td>
                <input type="text" name="religion" ></input>
            </td>
        </tr>
    </table><br>
    <table>
        <tr>
            <td>
                Nationality: 
            </td>
            <td>
                <input type="text" name="nationality" ></input>
            </td>
        </tr>
        <tr>
            <td>
                Email Address: 
            </td>
            <td>
                <input type="text" name="email" ></input>
            </td>
        </tr>
    </table><br>
    <table>
        <tr>
            <td>
                Address 1:
            </td>
            <td> 
                <input type="text" name="address1" ></input>
            </td>
        </tr>
        <tr>
            <td>
                Address 2: 
            </td>
            <td>
                <input type="text" name="address2"></input>
            </td>
        </tr>
    </table><br>
    <table>
        <tr>
            <td>
                Course: 
            </td>
            <td>
                <input type="text" name="course" ></input>
            </td>
        </tr>
        <tr>
            <td>
                School Graduated: 
            </td>
            <td>
                <input type="text" name="school" ></input>
            </td>
        </tr>
    </table><br>
    <table>
        <tr>
            <td>
                Remarks: 
            </td>
            <td>
                <input type="text" name="remarks"></input>
            </td>
            </tr>
        </table><br>
            <input type="submit" value="Submit"></input>
        </form>


    </body>
    </html>';

        }
        else {  header('Location: /practice1/index.php');
        }



        ?>

this is the entire page of php

  • 写回答

6条回答 默认 最新

  • drpmazn9021 2016-05-21 07:58
    关注

    There is an error in your sql string. INSERT INTO table VALUES(..,..);

    $query = "INSERT INTO `crew_info` VALUES (first_name,middle_name,last_name,age,birth_date,birth_place,gender,martial_status,religion,nationality,email_address,address_1,address_2,course,school_graduated,remarks,date_added,crew_status) VALUES ('$first_name','$middle_name','$last_name','$age','$birth_date','$birth_place','$gender','$martial_status','$religion','$nationality','$email','$address1','$address2','$course','$school','$remarks','$date_added','PENDING')";
    
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路