PHP查询不会插入数据库,其他2个查询正在运行

时间:2018-11-16 10:21:06

标签: php mysql

所以我在这里有一些查询,我认为它们正在工作,这里的问题是我似乎无法使插入工作正常。

我在查询中没有看到任何错误,因为在浏览器中也没有返回任何错误。

接下来,我正在获取我的数据,因为它正在回显给我,关于我的错误在哪里的任何想法?还有有关如何避免这种错误的任何提示。

谢谢!

<?php
    require  '../api/dbcon.php';
    require  '../api/dbcon.php';


    require 'testfaculty.php';

    if(isset($_POST['submit'])){

    date_default_timezone_set('Asia/Hong_Kong');
    $todaysSerialCode='';


        if($conn->connect_error){
            die("Connection Failed: " . $conn->connect_error);
        }
        /*GETTING LATEST SERIAL CODE LAST VALUE
            -query database
            -if no result is given/null then the assumption is the there are no serialcode created for that date
            -if there are no serial code then append int 01 else then add one to the latest value
        */
        $todaysSerialCode = substr($_POST['campus'], 0, 2) . date('y') . date('m') . date('d');
        $stmt1=$conn->prepare("SELECT MAX( SerialCode ) AS max FROM joborder where SerialCode LIKE ?");
        $stmt1->bind_param('s',$searchForLatestSerialCode);
        $searchForLatestSerialCode= $todaysSerialCode . '__';
        $stmt1->execute();
        $stmt1->bind_result($latestSerialCode);
        if($stmt1->fetch()){
        // getting the last 2 digits of the serial code and adding 1
        $latestSerialNum = substr($latestSerialCode, 8,10)+1;
         /*
            in adding one for example
            04 + 1 the result would be 4
            so we need to append again a zero below
            so if the length of the value is less than or equal to one 
            we append a zero in front of it
         */
         if(strlen($latestSerialNum)<=1)
            $latestSerialNum = '0'.$latestSerialNum;
        //appending the latest number
             $todaysSerialCode = $todaysSerialCode . $latestSerialNum;
        }else{
            $todaysSerialCode = $todaysSerialCode . '01';
        }

    $stmt1->close();
    $conn->close();


    require '../api/dbcon.php';
        $stmt2=$conn->prepare("SELECT Id FROM priority where Name = ?");
        $stmt2->bind_param('s', $priority);
        $priority = $_POST["priority"];
        //echo $priority;
        $stmt2->execute();
        $stmt2->bind_result($priorityId);
        $stmt2->fetch();

    $stmt2->close();
    $conn->close();



          $priorityId;
        //now inserting data
    require '../api/dbcon.php';

        $stmt=$conn->prepare("INSERT INTO joborder (AirCondition,
                                                   CarpentryMasonry,
                                                   ElectricalWorks,
                                                   Plumbing,
                                                   Welding,
                                                   Campus,
                                                   priorityId, 
                                                   RequestorName,
                                                   UserJobDescription,
                                                   SerialCode,
                                                   statusId,
                                                   DateRequestCreated,
                                                   NameOfOffice
                                                   ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" );
        // if($stmt){
        // echo "<script type='text/javascript'>
        //             alert ('Successful insertion of data'); 
        //             window.location.href='faculty-job-order-form.php';</script>";
        // }else{
        // echo "<script type='text/javascript'>
        //             alert ('Not Successful insertion of data'); 
        //             window.location.href='faculty-job-order-form.php';</script>";
        // }                                    
    $stmt->bind_param('sssssssssssss',
                        $airConditioning,
                        $masonryCarpentry,
                        $electrical,
                        $plumbing,
                        $welding,
                        $campus,
                        $priority,
                        $requester,
                        $userJobDescription,
                        $serialCode,
                        $statusId,
                        $DateRequestCreated,
                        $NameOfOffice);

    echo $airConditioning = isset($_POST['air-conditioning']) ? "checked" : '';
    echo $masonryCarpentry = isset($_POST['masonary-carpentry']) ? "checked" : '';
    echo $electrical = isset($_POST['Electrical']) ? "checked" : '';
    echo $plumbing = isset($_POST['Plumbing']) ? "checked" : '';
    echo $welding = isset($_POST['Welding']) ? "checked" : '';
    echo $campus =  $_POST['campus'];
    echo $priority =  $priorityId;
    echo $requester = $_SESSION['usr_fullname'];
    echo $userJobDescription = $_POST['user-job-description'];
    //create serial code
    echo $serialCode= $todaysSerialCode;
    echo $statusId = 7 ;
    echo $DateRequestCreated = date('y-m-d');
    echo $NameOfOffice = isset($_POST['college']) ? $_POST['college'] : '';
    $stmt->execute();
    $stmt->close();
    $conn->close();
    }


    ?>

0 个答案:

没有答案