0

I have php page to enter some details of audit and finally save in database.But when i entered the data,and press the save button.But it doesn't get saved in database.When i use error_log() function to check whether php function is working or not as below, in my log file only "Started" is there.. their is no "submitted" and further database error message.

Note: im new to php,started to develop php application using xampp and notepad++

auditentry.php

 <?php
    include("config.php"); 
    include("header.php"); 
    session_start();
    error_log("started");
    ?>

<link href="<?=BASE_URL?>bootstrap/css/bootstrap.css" rel="stylesheet"> 
<link rel="stylesheet" href="<?=BASE_URL?>/bootstrap/css/bootstrap.min.css">
 <script type="text/javascript" src="<?=BASE_URL?>js/jquery.js"></script> 
<script src="<?=BASE_URL?>bootstrap/js/bootstrap.js"></script>  
 <link href="<?=BASE_URL?>bootstrap/css/bootstrap-responsive.css" rel="stylesheet">

<div class="col-md-10 main">     

<h1 class="page-header">
   Audit Plan  Entry          
 </h1>      
     <form class="form-horizontal" role="form">
    <div class="form-group">
      <label class="control-label col-sm-2" for="usr">Audit ID:</label>  
        <div class="col-sm-5"> 
          <input  type="text" class="form-control" id="auditid" name ="auditid" placeholder="Eg: IA01">
        </div>
    </div>
    <div class="form-group">
      <label class="control-label col-sm-2" for="pwd">Year:</label>
        <div class="col-sm-5">
            <input type="text" class="form-control col-xs-3" id="year" name ="year">
        </div>
    </div>
    <div class="form-group">
      <label class="control-label col-sm-2" for="usr">Month:</label>
        <div class="col-sm-5">
            <input  type="text" class="form-control" id="month" name ="month">
        </div>
    </div>
     <div class="form-group">
      <label class="control-label col-sm-2 " for="sel1">Status:</label>
        <div class="col-sm-5">
          <select class="form-control" id="sel1" name="status">
            <option>Planned</option>
            <option>Scheduled</option>
            <option>Completed</option>
            <option>Cancelled</option>
          </select>
        </div>
    </div>

     <div class="form-group">
      <label class="control-label col-sm-2" for="comment">Comment:</label>
        <div class="col-sm-5">
            <textarea class="form-control" rows="3" id="comment" name="comment"></textarea>
        </div>
    </div>  

    <div class="form-group">        
          <div class=" col-sm-offset-3">
            <button type="submit" name="submit" id ="submit" class="btn btn-primary">Save</button>
            <button type="reset" name="submit1" id ="clear" class="btn btn-primary">Cancel</button>
          </div>

     </div>     
    </form>           
    </div>

    <?php
        if(isset($_POST['submit']))
            { 
        error_log("Submitted");
                    if(trim($_POST['auditid'])=='')
                        {
                echo "<script language='javascript'>alert('Please Enter Audit ID.');</script>";
                exit;
                        }                   
                elseif(trim($_POST['year'])=='')
                        {
                echo "<script language='javascript'>alert('Please Enter Year.');</script>";
                exit;
                        }
                elseif(trim($_POST['month'])=='')
                        {
                echo "<script language='javascript'>alert('Please Enter Month.');</script>";
                exit;
                        }
                elseif(trim($_POST['Status'])=='None')
                        {
                echo "<script language='javascript'>alert('Please Enter Status.');</script>";
                exit;
                        }
                $audit=trim($_REQUEST['auditid']);
                $year=trim($_REQUEST['year']);
                $month=trim($_REQUEST['month']);        
                $status =$_REQUEST['status'];
                $comment=$_REQUEST['comment'];  

                error_log($audit);


            $con = mysql_connect("localhost","root","") or die("Sorry you are not connected to server. Try Again!");
             mysql_select_db("simauditdb", $con) or die ("Cannot connect to database.");


            $insert=  "insert into auditplan 
            values('','$audit','$year','$month','$status','$comment','1')"; 

            error_log($insert);

                $result=mysql_query($insert) or die('Connection Failed'.mysql_error());
                echo "<script language='javascript'>alert('Audit Details Entered Successfully');</script>";     

                mysql_close($con); 

            }
        elseif(isset($_POST['submit1']))
                {
                echo "<script language='javascript'>document.location.href='Auditplan.php';</script>";
                }           
    ?>
2
  • What database error you got?? If you are new to php then stop learning deprecated mysql instead use mysqli or PDO Commented Dec 26, 2015 at 6:49
  • advice: mysql_* is outdated and is removed from PHP. use mysqli or PDO Commented Dec 26, 2015 at 6:54

1 Answer 1

2

You didnt specify the form action and method. <form class="form-horizontal" role="form"> Try this

<form action="" method="post" lass="form-horizontal" role="form">

You are posting the values, but you forgot to specify the form method.

Sign up to request clarification or add additional context in comments.

1 Comment

Default action is the URL relative to the URL containing the form and default method is GET. So technically both do not need to be specified. For the action, you can leave it out in your answer and for the method, you only need to set it to post if get is unwanted (GET should be unwanted, as updating data should be a POST operation). So this could be a bit more precise worded. Also please provide reference to the statements you give like W3C source and the PHP manual so that new users can source wisdom on their own as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.