0

UPDATE.php

<?php 
    include('DB.php');
    if(isset($_GET['id'])){
        $id=$_GET['id'];
        if(isset($_POST['update'])){
           $name=mysqli_real_escape_string($link,$_POST["ename"]);
           $email=mysqli_real_escape_string($link,$_POST["eemail"]); 
           $enpassword=mysqli_real_escape_string($link,$_POST["epassword"]);
           $dateofbirth=mysqli_real_escape_string($link,$_POST["edateofbirth"]);
           $mobile=mysqli_real_escape_string($link,$_POST["emobile"]);
           $presentaddress=mysqli_real_escape_string($link,$_POST["epresentaddress"] );
           $drivinglicense=mysqli_real_escape_string($link,$_POST["edrivinglicense"]);

           if(mysqli_query("UPDATE hrmsinfo SET emp_name=$name,emp_email=$email,emp_password=$enpassword,emp‌​_dob=$dateofbirth,em‌​p_phno=$mobile,emp_a‌​ddress=$presentaddress,emp_proof=$drivin‌​glicense WHERE emp_id='$id'")){
               $msg="Successfully Updated!!";
               header('Location:VIEW.php');
           }
           else{
               $msg="Unsucessfull!!";
           }
       }
    }  //update ends here
    ?>

When ever i try to execute this update code with following edit code it displays blank page help me with it

The below is edit code which executes perfectly but update doesnt work at all help me where am i stuck

<?php 

//error_reporting(0);
include("DB.php");
if(isset($_GET['id'])){
     $id=$_GET['id'];
     $sql="SELECT * FROM hrmsinfo WHERE emp_id='$id'";
     $sqll=mysqli_query($link,$sql);
     while($profile=mysqli_fetch_array($sqll)){
         $username=$profile['emp_name'];
         $usermail=$profile['emp_email'];
         $userdob=$profile['emp_dob'];
         $usermobile=$profile['emp_phno'];
         $useraddress=$profile['emp_address'];
         $userproof=$profile['emp_proof'];
?>

<div>

<form action="UPDATE.php" method="post" name="insertform">


       <div class="form-group">
                  <div class="row">
                    <div class="col-xs-3">Name:</div>
                    <div class="col-xs-4"><input type="text" class="form-control" name="ename" placeholder="Enter Name" value="<?php echo $username; ?>" id="inputid"></div>
                  </div>
                </div>



                <div class="form-group">
                  <div class="row">
                    <div class="col-xs-3">Email:</div>
                    <div class="col-xs-4"><input type="text" class="form-control" name="eemail" placeholder="Enter Email" value="<?php echo $usermail; ?>" id="inputid"></div>
                  </div>
                </div>

                <div class="form-group">
                  <div class="row">  
                    <div class="col-xs-3">Password:</div>
                    <div class="col-xs-3"><input type="password" class="form-control" name="epassword" id="inputid" placeholder="Enter Password" id='input_id'></div>
                    <div class="col-xs-3"><input type="password" class="form-control" name="epassword" id="inputid" placeholder="Re-Enter Password" id='input_id'></div>
                    <div class="col-xs-3">
                    <div class="checkbox"><input type="checkbox"> Auto Generate</div>
                    </div>
                  </div>
                </div>

                <div class="form-group">
                  <div class="row">
                    <div class="col-xs-3">Date Of Birth:</div>
                      <div class="col-xs-5">
                        <div class="input-group date">
                        <div class="input-group-addon">
                          <i class="fa fa-calendar"></i>
                            </div>
                        <input type="date" class="form-control pull-right" name="edateofbirth" value="<?php echo $userdob; ?>" id="inputid">
                      </div>
                    </div>
                  </div>
                </div>








      <div class="form-group">
                  <div class="row"> 
                    <div class="col-xs-3">Mobile Number:</div>
                    <div class="col-xs-5">
                      <input type="text" class="form-control" placeholder="Enter Mobile" name="emobile" value="<?php echo $usermobile; ?>" id="inputid">
                    </div>
                  </div>
      </div>



              <div class="form-group">
                  <div class="row"> 
                    <div class="col-xs-3">Address:</div>
                      <div class="col-xs-5"> 
                      <textarea class="form-control" rows="3" placeholder="Enter Address"  name="epresentaddress" value="<?php echo $useraddress; ?>" id="inputid"></textarea>
                    </div>
                  </div>
                </div>





      <div class="form-group">
                  <div class="row"> 
                    <div class="col-xs-3">Proof:</div>
                     <div class="col-xs-5"> 
                      <input type="text" class="form-control" placeholder="Enter Proof"  name="edrivinglicense" value="<?php echo $userproof; ?>" id="inputid">
                    </div>
                  </div>
                </div>




      <div class="form-group">
        <div class="row"> 
          <div class="col-xs-3"></div>
            <div class="col-xs-5">
              <input type="submit" name="update" value="Update" id="inputid1" />
            </div>
          </div>
        </div>


  </form>

</div>

<?php } } ?>

Please help me with proper guidance where am i stuck here or i am making mistake

conventi
  • 430
  • 3
  • 8
Jinam Shah
  • 31
  • 7
  • 1
    Have you done any debugging? Are there any errors? – Tom Jan 09 '17 at 09:11
  • may be your control is going in unsuccessful where there is no echo message placed. Please put echo message at the first line of if and else and you will might get to see echoed message – Sandeep Garg Jan 09 '17 at 09:13
  • enable display of errors, also you don't have any handler if there no $_GET['id'], so maybe it's just absent – justtry Jan 09 '17 at 09:25
  • Hi ,there are 2 possibilities: 1) your 1st if statement fails because you did not pass id and that provides no output. 2) you have some php error and your error reporting is disabled. I would suggest to echo out your id just before the if statement to see if that one is passed in correctly. – Auris Jan 09 '17 at 09:34

1 Answers1

0

as per your code you put one condition i.e.

if(isset($_GET['id']))
    {
     .....
}

but in html form you are not pass any id field add id field and try your condition will verify and update will work. just add one field like below.. remaining is same.

    <form action="UPDATE.php?id=<?php echo $id; ?>" method="post" name="insertform">
    <input type="hidden" name="id"  value="<?php echo $id; ?>" >
   ...............
.................
</form>

Note: In HTML page id of field should be unique.

Jigar Patel
  • 197
  • 6