Как мне сделать это, чтобы я мог редактировать таблицу? - PullRequest
0 голосов
/ 18 апреля 2019

Я создаю таблицу в php, в которую пользователи могут войти и редактировать записи. У меня есть вся информация для отображения, но я не могу ее отредактировать.

<table id="example" class="display responsive-table ">
   <thead>
       <tr>
           <th>#</th>
            <th width="95">Employee Type</th>
            <th width="95">Firstname</th>
            <th width="95">Lastname</th>
            <th width="95">Email</th>
            <th width="95">Phone</th>
            <th width="95">Address</th>
            <th width="95">City</th>
            <th width="95">Country</th>
            <th width="95">Dob</th>
            <th width="95">Description</th>
            <th width="95">Update</th>
            <th width="95">Delete Employee</th>
        </tr>
   </thead>
   <tbody>
        <?php 
            $eid=$_SESSION['eid'];
            $sql = "SELECT LeaveType, ToDate, FromDate, email, phone, address, city, country, dob, Description, Status
                    FROM tblleaves
                    WHERE empid=:eid";
            $query = $dbh -> prepare($sql);
            $query->bindParam(':eid',$eid,PDO::PARAM_STR);
            $query->execute();
            $results=$query->fetchAll(PDO::FETCH_OBJ);
            $cnt=1;
            if($query->rowCount() > 0) {
                foreach($results as $result) { ?>  
                    <tr>
                        <td> <?php echo htmlentities($cnt);?></td>
                         <td><?php echo htmlentities($result->LeaveType);?></td>
                         <td><input id="todate" name="todate" type="text"  value="<?php echo htmlentities($result->ToDate);?>" autocomplete="off" required></td>
                         <td><input id="formdate" name="fromdate" type="text"  value="<?php echo htmlentities($result->FromDate);?>" autocomplete="off" required></td>
                         <td><input id="email" name="email" type="text"  value="<?php echo htmlentities($result->email);?>" autocomplete="off" required></td>
                         <td><input id="phone" name="phone" type="tel"  value="<?php echo htmlentities($result->phone);?>" autocomplete="off" required></td>
                         <td><input id="address" name="address" type="text"  value="<?php echo htmlentities($result->address);?>" autocomplete="off" required></td>
                         <td><input id="city" name="city" type="text"  value="<?php echo htmlentities($result->city);?>" autocomplete="off" required></td>
                         <td><input id="country" name="country" type="text"  value="<?php echo htmlentities($result->country);?>" autocomplete="off" required></td>
                         <td><input id="dob" name="dob" type="text"  value="<?php echo htmlentities($result->dob);?>" autocomplete="off" required></td>
                         <td><input id="description" name="description" type="text"  value="<?php echo htmlentities($result->Description);?>" autocomplete="off" required></td>
                         <td><button type="submit" name="update"  id="update" class="waves-effect waves-light btn indigo m-b-xs">UPDATE</button></td>
                         <td><a href="leavehistory.php?del=<?php echo htmlentities($result->id);?>" onclick="return confirm('Do you want to delete');"> <i class="material-icons">delete_forever</i></a></td>
                     </tr>
                 <?php 
                     $cnt++; 
                 }
             } 
         ?>
   </tbody>
</table>

Таблица должна показывать вам записи пользователей и позволять пользователю изменять их.

спасибо, что теперь он работает и успешно публикует, но не обновляет базу данных

Вот мой код обновления:

$eid=intval($_GET['empid']);
if(isset($_POST['update']))
{

$todate=$_POST['todate'];
$fromdate=$_POST['fromdate'];   
$email=$_POST['email']; 
$phone=$_POST['phone']; 
$address=$_POST['address']; 
$city=$_POST['city']; 
$country=$_POST['country']; 
$dob=$_POST['dob']; 
$description=$_POST['description']; 
$sql="update tblleaves set ToDate=:todate,FromDate=:fromdate,email=:email,phone=:phone,address=:address,city=:city,country=:country,dob=:dob,Description=:description where empid=:eid";
$query = $dbh->prepare($sql);
$query->bindParam(':todate',$todate,PDO::PARAM_STR);
$query->bindParam(':fromdate',$formdate,PDO::PARAM_STR);
$query->bindParam(':email',$email,PDO::PARAM_STR);
$query->bindParam(':phone',$phone,PDO::PARAM_STR);
$query->bindParam(':address',$address,PDO::PARAM_STR);
$query->bindParam(':city',$city,PDO::PARAM_STR);
$query->bindParam(':country',$country,PDO::PARAM_STR);
$query->bindParam(':dob',$dob,PDO::PARAM_STR);
$query->bindParam(':description',$description,PDO::PARAM_STR);
$query->bindParam(':eid',$eid,PDO::PARAM_STR);
$query->execute();
$msg="Employee record updated Successfully";
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...