doudi4137 2018-11-16 10:21
浏览 24

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

so I have a few query down here and I think they are working, the problem here is that I can't seem to make the insertion work.

I do not see any errors in my query as there are also no errors being returned in my browser.

Next is I am getting my data cause it is being echo back to me, any ideas on where my errors are? also any tips on how to avoid this mistakes.

Thanks!

<?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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大