无法提交php表单

时间:2018-01-22 10:17:45

标签: php phpmyadmin

我有三个文件

  • leaveform.php
  • leavefrom.tpl
  • leaveform.class.php

我将发送以下编码。请找到并解决这个问题。

leaveform.php

 <?php
    include_once 'init.php';

    include CLASS_DIR."leaveform.class.php";
    $leaveformObj   = new leaveform;
    $email              = '';
    $password           = '';
    $err_msg            = '';
    $s_msg              = '';
    $verfication_code   = '';
    if(isset($_POST['leaveSubmit'])){
            $branch   = $_POST['branch'];
        $date   = $_POST['date'];
        $name   = $_POST['name'];
        $designation    = $_POST['designation'];
        $employeeid         = $_POST['employeeid'];
        $noofdays           = $_POST['noofdays'];
        $from           = $_POST['from'];
        $to         = $_POST['to'];
        $reasonforleave         = $_POST['reasonforleave'];
        $address        = $_POST['address'];
        $contactno          = $_POST['contactno'];
        $approvedby         = $_POST['approvedby'];
        if(empty($branch)){
            $err_msg = "Please select your branch";
        }elseif(empty($date)){
        $err_msg = "Please select The Date";}
    else {

            $leaveformObj->branch   = $branch;
                $leaveformObj->date     = $date;
            $leaveformObj->name     = $name;
            $leaveformObj->designation          = $designation;
            $leaveformObj->employeeid           = $employeeid;
            $leaveformObj->noofdays         = $noofdays;
            $leaveformObj->from         = $from;
            $leaveformObj->to           = $to;
            $leaveformObj->reasonforleave           = $reasonforleave;
            $leaveformObj->address          = $address;
            $leaveformObj->contactno            = $contactno;
            $leaveformObj->approvedby           = $approvedby;


            $addleave      = $leaveformObj->addleave(); //Login as Church Admin 
            if($addleave){
                $leaveformObj->ticket_no     = "Ticket#".$addleave;
                $leaveformObj->leave_id  = $addleave;
                $Ticket      = $leaveformObj->updateTicket();
                if ($Ticket) {
                $s_msg = "Successfully Submitted<br>";
                $s_msg .= "Your Ticket No : Ticket#".$addleave;
                }

            }else{
                $err_msg = "Invalid leaveform details";
            }
        }
    }
    $smarty->assign('s_msg', $s_msg);
    $smarty->assign('err_msg', $err_msg);
    $smarty->display('leaveform.tpl'); 
    ?>

leaveform.tpl

{include file="inc/main_header.tpl"}
<style type="text/css">
option {
    text-transform: capitalize;
}
.nopadding div{
    padding: 0px !important;
}
form[role="login"] input.inputText{
    padding: 0;
    border: 0;
    background: none;
    border-bottom: 1px dotted;
    box-shadow: none;
    border-radius: initial;
    width: 85%;
}
form[role="login"] .threeCol input.inputText{
    width: 68%;
}
</style>
<div class="wrapper">
<!-- Left side column. contains the logo and sidebar -->
    <div class="container">
    <div class="col-md-12">
                            <!--breadcrumbs start -->
        <!--<ul class="breadcrumb front">
            <li><a href="#"><i class="fa fa-home"></i> Home</a></li>
            <li class="active"><a href="#">Admin Login</a></li>
        </ul>-->
        <!--breadcrumbs end -->
    </div>
        <section class="col-md-12">

            <div class="panel panel-default">

                <div class="panel-body">
                    <form method="post" action="" role="login" id="FormValidate">
                    <div class="col-md-3">
                        <img src="images/krishnasweet.png" alt="Krishna Sweet" class="" width='180'>
                    </div>
                    <div class="col-md-6">
                        <h3 style="text-align: center;color: blue;font-style: italic;">Leave Application Form<br></h3>
                    </div>
                 {if $s_msg}
                <p style="text-align: center; color:green;">{$s_msg}</p>
                {elseif $err_msg}
                <p style="text-align: center; color:red;">{$err_msg}</p>
                {/if}
                <div class="col-md-12" style="min-height:30px;"></div>
                <div class="col-md-3">&nbsp;</div>
<div class="col-md-15" >    
<div class="col-md-12 nopadding">   
<div class="col-md-6"><label style="display: inline-block;">Branch :</label><input type="text" class="inputText" name="branch"></div>
<div class="col-md-6"><label style="display: inline-block;">Date :</label><input type="date" class="inputText" name="date"></div>

</div>          
<div class="col-md--1">&nbsp;</div>
    </div>
<div class="col-md--1">&nbsp;</div>
<div class="col-md--1" >        
<div class="col-md--1">
    </div>
</div>
<div class="col-md--1">&nbsp;</div>
<div class="col-md-2" >     


</div>
<div class="col-md-12 nopadding">
    <div class="col-md-8"><label style="display: inline-block;">Name :</label><input type="text" class="inputText" name="name"></div>
    <div class="col-md-8"><label style="display: inline-block;">Designation:</label><input type="text" class="inputText" name="designation"></div>
    </div><div class="col-md-12 nopadding">
    <div class="col-md-7"><label style="display: inline-block;">Employee ID :</label><input type="text" class="inputText" name="employeeid"></div>
</div>
<div class="col-md-12 threeCol nopadding">
    <div class="col-md-4"><label style="display: inline-block;">No.Of.Days:</label><input type="text" class="inputText" name="noofdays"></div>
    </div><div class="col-md-12 threeCol nopadding">
    <div class="col-md-4"><label style="display: inline-block;">From:</label><input type="date" class="inputText" name="from" ></div>
    <div class="col-md-4"><label style="display: inline-block;">To:</label><input type="date" class="inputText" name="to" ></div>

</div>
<div class="col-md-12 nopadding">
    <div class="col-md-12"><label style="display: inline-block;">Reason For Leave:</label><input type="text"  class="inputText" name="reasonforleave" "></div>
        <div class="col-md-12"><label style="display: inline-block;">Address:</label><input type="text"  class="inputText" name="address" "></div>
    </div>
    <div class="col-md-9"><label style="display: inline-block;">Contact No:</label><input type="text" class="inputText" name="contactno"></div>
    <div class="col-md-9"><label style="display: inline-block;">Approved By:</label><input type="text" class="inputText" name="approvedby"></div>
</div>
                        <button type="submit" name="leaveSubmit" class="btn btn-block btn-info">Submit</button>
                    </form>
                </div>
            </div>
        </section>
    </div>
</div>

{include file="inc/main_footer.tpl"}
<script>
    $(document).ready(function(){
        $(document).on("change","#categorySection",function(event) {
            var _val = $(this).val();           
            if(_val != ""){
                $("#subCategorySection option").hide();
                $("#subCategorySection option[data-cat="+_val+"]").show();
                $("#subCategorySection").removeAttr("disabled");
            }
        });     
    });
</script>

leaveform.class.php

 <?php 
class leaveform
{
     var $leave_id;
     var $branch;
     var $date;
     var $name;
     var $designation;
     var $employeeid;
     var $noofdays;
     var $from;
     var $to;
     var $reasonforleave;
     var $address;
     var $contactno;
     var $approvedby;

    function complaints($leave_id = '')
    {
        global $db,$smarty;
        if ( $leave_id )
        {
            $this->leave_id = $leave_id;
            $sql = "SELECT * FROM leaveform WHERE leave_id=$this->leave_id";
            $leaveform = $db->getRow($sql);
            if($leaveform != null) 
            { 
                $this->leave_id = trim(stripslashes($leaveform['leave_id']));
                $this->branch = trim(stripslashes($complaints['branch']));
                $this->date = trim(stripslashes($complaints['date']));
                $this->name = trim(stripslashes($complaints['name']));
                $this->designation = trim(stripslashes($complaints['designation']));
                $this->employeeid = trim(stripslashes($complaints['employeeid']));
                $this->noofdays = trim(stripslashes($complaints['noofdays']));
                $this->from = trim(stripslashes($complaints['from']));
                $this->to = trim(stripslashes($complaints['to']));
                $this->reasonforleave = trim(stripslashes($complaints['reasonforleave']));
                $this->address = trim(stripslashes($complaints['address']));
                $this->contactno = trim(stripslashes($complaints['contactno']));
                $this->approvedby = trim(stripslashes($complaints['approvedby']));
            }
        }else {

            $this->leave_id = "";
            $this->branch = "";
            $this->date = "";
            $this->name = "";
            $this->designation = "";
            $this->employeeid = "";
            $this->noofdays = "";
            $this->from = "";
            $this->to   = "";
            $this->reasonforleave   = "";
            $this->address  = "";
            $this->contactno    = "";
            $this->approvedby   = "";
        }
    }
    /***
    Add Church Admin
    Used Php Files : Index.php
    ***/
    function addleave()
    { 
        global $db, $smarty;
        $sql = "INSERT INTO leaveform(branch,date,name,designation,employeeid,noofdays,from,to,reasonforleave,address,contactno,approvedby) VALUES 
        ('$this->branch','$this->date', '$this->name','$this->designation','$this->employeeid','$this->noofdays','$this->from','$this->to','$this->reasonforleave','$this->address',
        '$this->contactno','$this->approvedby')";
        $result    = $db->Execute($sql);
        $leave_id = $db->insert_ID();
        if($result)
        {
            return $leave_id;
        }else{
            return 0;
        }   
    } 
        function updateTicket()
    { 
        global $db, $smarty;
        $sql = " UPDATE leaveform SET ticket_no = '$this->ticket_no' WHERE leave_id = '$this->leave_id' ";
        $leave_id = $db->Execute($sql);
        if($leave_id){
            return true;
        }else{
            return false;
        }
    } 


 } 
?>
我正在使用三个PHP代码。我在php表单中有无效细节的错误。 请帮助我解决这个问题..我是php的新手

1 个答案:

答案 0 :(得分:0)

失败是因为下面的代码。您基本上没有正确设置参数。

$sql = "INSERT INTO leaveform(branch,date,name,designation,employeeid,noofdays,from,to,reasonforleave,address,contactno,approvedby) VALUES 
    ('$this->branch','$this->date', '$this->name','$this->designation','$this->employeeid','$this->noofdays','$this->from','$this->to','$this->reasonforleave','$this->address',
    '$this->contactno','$this->approvedby')";
    $result    = $db->Execute($sql);
    $leave_id = $db->insert_ID();

没有人会为你调试它。打开php.ini中的“显示错误”选项。以下链接将为您提供帮助。 https://www.inmotionhosting.com/support/website/php-troubleshooting/troubleshoot-php-errors

这将开始显示页面本身的错误,您应该能够进行调试。

建议:使用PDO对象并绑定每个参数以更干净的方式执行脚本。