douting0585 2018-01-22 10:17
浏览 37

无法提交php表单

i have three files

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

i will send the codings below. olease find and solve this issue.

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;
        }
    } 


 } 
?>

i am using three php codes. i have a error with invalid details in php form. kindly help me to solve this issue..and i am new to php

  • 写回答

1条回答 默认 最新

  • duankang5285 2018-01-22 12:15
    关注

    The failure is because of the below piece of Code. You are basically not setting the parameters correctly.

    $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();
    

    No one would go around debugging it for you. Turn on the "Show errors" options in your php.ini. The below link will help you. https://www.inmotionhosting.com/support/website/php-troubleshooting/troubleshoot-php-errors

    This will start showing the errors in the page itself and you should be able to debug.

    Advice: Use PDO objects and bind every parameter to execute script in a cleaner way.

    评论

报告相同问题?

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗