Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<?php
 //include('editheader.php');
// including the database connection file
include_once("config.php");

if(isset($_POST['update']))
{   

    $id = mysqli_real_escape_string($conn, $_POST['id']);
    
    $empname = mysqli_real_escape_string($conn, $_POST['empname']);
    $empcontact = mysqli_real_escape_string($conn, $_POST['empcontact']);
     $customer_name = mysqli_real_escape_string($conn, $_POST['customer_name']);
     $dates = mysqli_real_escape_string($conn, $_POST['dates']);
     $tyme = mysqli_real_escape_string($conn, $_POST['tyme']);
     

     

    
    // checking empty fields
    if(empty($empname) || empty($empcontact) || empty($expertise)) {  
            
        if(empty($name)) {
            //echo "<font color='red'>Name field is empty.</font><br/>";
        }
        
        if(empty($age)) {
            //echo "<font color='red'>Age field is empty.</font><br/>";
        }
        
        if(empty($email)) {
           // echo "<font color='red'>Email field is empty.</font><br/>";
        }       
    } else {    
        //updating the table
        $result = mysqli_query($conn, "UPDATE booking SET empname='$empname',empcontact='$empcontact',customer_name='$costomer_name',dates='$dates',tyme='$tyme' WHERE id=$id");
        
        //redirectig to the display page. In our case, it is index.php
        echo "Record updated Successfully!!!!";
        header("Location: viewAppointment.php");
    }
}
?>
<?php
//error_reporting(0);
//getting id from url
$id = $_GET['id'];


//selecting data associated with this particular id
$result = mysqli_query($conn, "SELECT * FROM booking WHERE id = {$id}");


while($res = mysqli_fetch_array($result))
{
    $empname = $res['empname'];
    $empcontact = $res['empcontact'];
    
    $customer_name = $res['customer_name'];
    
    $dates= $res['dates'];
    $tyme= $res['tyme'];
}


?>
<html>
<head>  
    <title>Edit Data</title>
</head>

<body>
    <a href="viewAppoinment.php">Home</a>
    <br/><br/>
    
    <form name="form1" method="post" action="appedit.php">
        <table border="0">
            <tr> 
                <td>Employee.Name</td>
                <td><input type="text" name="empname" value="<?php echo $empname;?>"></td>
            </tr>
            <tr> 
                <td>employee contact:</td>
                <td><input type="text" name="empcontact" value="<?php echo $empcontact;?>"></td>
            </tr>
            <tr> 
                <td>CustomerName:</td>
                <td><input type="text" name="customer_name" value="<?php echo $customer_name;?>"></td>
            </tr>
           
            <tr> 
                <td>Day:</td>
                <td><input type="date" name="dates" value="<?php echo $dates;?>"></td>
            </tr>
            <tr> 
                <td>Time</td>
                <td><input type="text" name="tyme" value="<?php echo $tyme;?>"></td>
            </tr>
            
            
            <tr>
                <td><input type="hidden" name="id" value=<?php echo $_GET['id'];?>></td>
                <td><button name="update">Update</button></td>
            </tr>
        </table>
    </form>
</body>
</html>


What I have tried:

I have tried more procedures but I'm failing
Posted
Updated 9-Aug-21 17:21pm
Comments
Sandeep Mewara 7-Aug-20 5:23am    
Does this help, similar query: https://www.codeproject.com/Questions/1233256/What-can-I-do-to-fix-warning-mysqli-fetch-array-ex
Richard Deeming 7-Aug-20 6:02am    
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

PHP: SQL Injection - Manual[^]
PHP: Prepared statements and stored procedures - Manual[^]

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900