-1

Trying to update employee information by using employee id (emp_id).

I have written the update query below. I have checked the table name and database details all are correct but for some reason update query is not running.

Is there any method to solve this issue?

<?php

session_start();
$id=$_SESSION['SESS_MEMBER_ID'];
//echo $id;
require_once('auth.php');
include('connection.php');
?>

<?php
$query2="SELECT * FROM add_employee where emp_id='$id'";
$result1=mysqli_query($conn, $query2);
while($row=mysqli_fetch_array($result1))
{ 
   fullname=$row['fullname'];
   $email=$row['email'];
   $contact=$row['contact'];
   $address=$row['address'];
   $designation=$row['designation'];
   //$client_name=$row['client_name'];
   $joining_date=$row['joining_date'];
   $password=$row['password'];
   //$aadhartoupload=$row['aadhar'];
   $filetoupload=$row['photo'];
   //$resumetoupload=$row['resume'];
}
//die();
?>

Get Employee information

<?php
if(isset($_POST['submit'])){            
   $fullname=$_POST['fullname'];
   $email=$_POST['email'];
   $contact=$_POST['contact'];
   $address=$_POST['address'];
   $designation=$_POST['designation'];
   //$client_name=$_POST['client_name'];
   $joining_date=$_POST['joining_date'];
   $password=$_POST['password'];

Employee information update query

$sqlq= "UPDATE add_employee SET 
           fullname='$fullname',
           email='$email',
           contact='$contact',
           address='$address',
           designation='$designation',
           joining_date='$joining_date',
           password='$password' 
       WHERE 
           emp_id=$id";

$sqlqry= mysqli_query( $sqlq, $conn );

if ($sqlqry) { 
    echo "<script type='text/javascript'>alert('Successful - Record Updated!'); window.location.href = 'user_profile.php';</script>"; 
 } else { 
    echo "<script type='text/javascript'>alert('Unsuccessful - ERROR!'); window.location.href = 'user_dashboard.php';</script>"; 
 }
}
?>
<!-- end of update profile code!-->

<form action="user_profile.php" method="post" enctype="multipart/form-data">
                                    <div class="row">
                                        <div class="col-md-3">
                                            <div class="form-group">
                                                <label>EMP ID</label>
                                                <input type="text" class="form-control border-input" id="emp_id" name="emp_id" placeholder="Employee Id" value="<?php echo $id; ?>" disabled>
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label>Fullname</label>
                                                <input type="text" class="form-control border-input" id="fullname" name="fullname" placeholder="fullname" value="<?php echo $fullname; ?>">
                                            </div>
                                        </div>
                                        <div class="col-md-5">
                                            <div class="form-group">
                                                <label>Email address</label>
                                                <input type="email" class="form-control border-input" name="email" placeholder="email" value="<?php echo $email; ?>">
                                            </div>
                                        </div>
                                    </div>

                                    <div class="row">
                                        <div class="col-md-3">
                                            <div class="form-group">
                                                <label>Contact number</label>
                                                <input type="text" class="form-control border-input" name="contact"placeholder="Contact" value="<?php echo $contact; ?>">
                                            </div>
                                        </div>
                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label for="exampleInputEmail1">Designation</label>
                                                <input type="text" class="form-control border-input" name="designation" placeholder="Your Designation" value="<?php echo $designation; ?>" disabled>
                                            </div>
                                        </div>
                                        <div class="col-md-5">
                                            <div class="form-group">
                                                <label>Client Name</label>
                                                <input type="text" class="form-control border-input" name="client_name" placeholder="Client Name" value="<?php echo $client_name; ?>" disabled>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label>Address</label>
                                                <input type="text" class="form-control border-input" name="address" placeholder="Address" value="<?php echo $address; ?>">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label>Joining Date</label>
                                                <input type="text" class="form-control border-input" name="joining_date" placeholder="Joining Date" value="<?php echo $joining_date; ?>" disabled>
                                            </div>
                                        </div>

                                        <div class="col-md-6">
                                            <div class="form-group">
                                                <label>Change password</label>
                                                <input type="password" class="form-control border-input" name="password" placeholder="Country" value="<?php echo $password; ?>">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <!--<div class="col-md-4">
                                            <div class="form-group">
                                                <label>Upload Aadhar</label>
                                                <input type="file" name="aadhar" id="aadhar" value="<?php //echo $aadhartoupload; ?>" >
                                            </div>
                                        </div>!-->
                                        <div class="col-md-4">
                                            <div class="form-group">
                                                <label>Upload photo</label>
                                                <input type="file" name="photo" id="photo" value="<?php echo $filetoupload; ?>" >
                                            </div>
                                        </div>
                                        <!--<div class="col-md-4">
                                            <div class="form-group">
                                                <label>Upload Resume</label>
                                                <input type="file" name="resume" id="resume" value="<?php //echo $resumetoupload; ?>" >
                                            </div>
                                        </div>!-->
                                    </div>



                                    <div class="text-center">
                                        <!--class="btn btn-info btn-fill btn-wd"!-->
                                        <button type="submit" name="submit" class="btn btn-info btn-fill btn-wd">Update Profile</button>
                                    </div>
                                    <div class="clearfix"></div>
                                </form>
  • 1
    Hi Rohit. Welcome to StackOverflow!. Can you please include any error messages? – Ahmad Dec 06 '18 at 05:50
  • 1) your code is wide open to sql injection attacks and if any of the input fields contain a single quote, then it will throw your query off 2) I do not see any forms that could be sumitted to update the data 3) where does $id come from? – Shadow Dec 06 '18 at 06:21
  • Hi Ahmad, Thank you for the reply, I did not get any error message after submitting the form I only get alert('Unsuccessful - ERROR!') – Rohit Kashyap Dec 06 '18 at 06:30
  • Hi Shadow, Thank you for instant reply, I have added the form in my question, Please check. – Rohit Kashyap Dec 06 '18 at 06:35
  • Well, in the else branch you could print out the actual error message and the you would know what's going on. – Shadow Dec 06 '18 at 06:45
  • print your query, run it in sql and check the result. – vaso123 Dec 06 '18 at 06:56
  • Hi Shadow, after submitting the form query printing the updated data but after refresh the page updated data will go off https://prnt.sc/lrdq6x – Rohit Kashyap Dec 06 '18 at 08:12
  • Getting below error Warning: mysqli_query(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in – Rohit Kashyap Dec 06 '18 at 08:25

1 Answers1

-1

I think you need to check your sql statement near WHERE emp_id=$id. Try rather using WHERE emp_id='$id'.Those quotes might be the difference.

Twista
  • 241
  • 3
  • 11