Am trying to create edit-form but there are some problem which I cant determine by my self. I cant echo inserted record and updating.

<?php

include("db_con.php");

$edit_reg_no = filter_input(INPUT_GET, 'edit_customer_detail', FILTER_VALIDATE_INT, ['options' => ['default' => NULL]]);

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

    $update_reg_no = $edit_reg_no;

    //getting the text data from the fields
    $d_fname = $_POST["d_fname"];
    $d_lname = $_POST["d_lname"];
    $customer_name = $_POST["customer_name"];
    $mobile = $_POST["mobile"];
    $office_tel = $_POST["office_tel"];
    $email_fax = $_POST["email_fax"];
    $model = $_POST["model"];
    $engine = $_POST["engine"];
    $vin = $_POST["vin"];
    $work_carry = $_POST["work_carry"];
    $demage_found = $_POST["demage_found"];
    $accessories = $_POST["accessories"];
    $car_received = $_POST["car_received"];
    $mileage_covered = $_POST["mileage_covered"];

    $update = "update customer_details set
    d_fname='$d_fname', d_lname='$d_lname', customer_name='$customer_name', mobile='$mobile', office_tel='$office_tel', email_fax='$email_fax', model='$model', engine = '$engine', vin = '$vin', work_carry = '$work_carry' demage_found = '$demage_found', accessories = '$accessories', car_received = '$car_received', mileage_covered = 'mileage_covered' where reg_no = '$update_reg_no'";

    $run = mysqli_query($con, $update);

    if($run)
    {
        echo "<script>alert('Customer details has been updated')</script>";
        echo "<script>window.open('index.php?view_all_customers','_self')</script>";
    }
    else
    {
        echo "<script>alert('There is something wrong! Details not Updated')</script>";
    }

}

?>

<!doctype html>
<html>
<head>

<meta charset="utf-8">
<title>Update Customer Details</title>
<link rel="stylesheet"  href="box_style.css" />
</head>

<body>
<?php
include("db_con.php");

    if(isset($_GET['edit_customer_detail'])){

        $edit_reg_no = $_GET['edit_customer_detail'];

        $select_customer_detail = "select * from customer_details where reg_no='$edit_reg_no'";

        $run_query = mysqli_query($con, $select_customer_detail);

        while ($row_customer_detail=mysqli_fetch_array($run_query)){

        $reg_no = $row_customer_detail['reg_no'];
        $d_fname = $row_customer_detail['d_fname'];
        $d_lname = $row_customer_detail['d_lname'];
        $customer_name = $row_customer_detail['customer_name'];
        $mobile = $row_customer_detail['mobile'];
        $office_tel = $row_customer_detail['office_tel'];
        $email_fax = $row_customer_detail['email_fax'];
        $model = $row_customer_detail['model'];
        $engine = $row_customer_detail['engine'];
        $vin = $row_customer_detail['vin'];
        $work_carry = $row_customer_detail['work_carry'];
        $demage_found = $row_customer_detail['demage_found'];
        $accessories = $row_customer_detail['accessories'];
        $car_received = $row_customer_detail['car_received'];
        $mileage_covered = $row_customer_detail['mileage_covered'];

        }
    }

?>

<div class='form'>
<form action="" method="post" enctype="multipart/form-data" >

<table width="745" align="center" border="2">

<p style="text-align: center;"><strong><span style="text-decoration: underline;">CUSTOMER DETAILS:</span></strong></p>

    <tr>        
        <td align="right" bgcolor="#dbe5f1"><strong>First Name:</strong></td>
        <td><input type="text" name="d_fname" id="d_fname" size="35" class="text" value="<?php echo $d_fname; ?>" /></td>      
    </tr>

    <tr>        
        <td align="right" bgcolor="#dbe5f1"><strong>Last Name:</strong></td>
        <td><input type="text" name="d_lname" id="d_lname" size="35" class="text" value="<?php echo $d_lname; ?>" /></td>
    </tr>

    <tr>        
        <td align="right" bgcolor="#dbe5f1"><strong>Customer Name:</strong></td>
        <td><input type="text" name="customer_name" id="customer_name" size="35"class="text" value="<?php echo $customer_name; ?>" /></td>     
    </tr>

    <tr>        
        <td align="right" bgcolor="#dbe5f1"><strong>Mobile:</strong></td>
        <td><input type="text" name="mobile" id="mobile" size="35" class="text" value="<?php echo $mobile; ?>" /></td>     
    </tr>

    <tr>        
        <td align="right" bgcolor="#dbe5f1"><strong>Office Tel:</strong></td>
        <td><input type="text" name="office_tel" id="office_tel" size="35" class="text" value="<?php echo $office_tel; ?>" /></td>     
    </tr>

    <tr>        
        <td align="right" bgcolor="#dbe5f1"><strong>Email/Fax:</strong></td>
        <td><input type="text" name="email_fax" id="email_fax" size="35" class="text" value="<?php echo $email_fax; ?>" /></td>        
    </tr>

    <tr>        
        <td align="right" bgcolor="#dbe5f1"><strong>Model:</strong></td>
        <td><input type="text" name="model" id="model" size="35" class="text" value="<?php echo $model; ?>" /></td>        
    </tr>

    <tr>        
        <td align="right" bgcolor="#dbe5f1"><strong>Engine:</strong></td>
        <td><input type="text" name="engine" id="engine" size="35" class="text" value="<?php echo $engine; ?>" /></td>     
    </tr>

    <tr>        
        <td align="right" bgcolor="#dbe5f1"><strong>VIN:</strong></td>
        <td><input type="text" name="vin" id="vin" size="35" class="text" value="<?php echo $vin; ?>" /></td>      
    </tr>

    <tr>        
        <td align="right" bgcolor="#dbe5f1"><strong>Car Received By:</strong></td>
        <td><input type="text" name="car_received" id="car_received" size="35" class="text" value="<?php echo $car_received; ?>" /></td>       
    </tr>

    <tr>        
        <td align="right" bgcolor="#dbe5f1"><strong>Mileage Covered:</strong></td>
        <td><input type="text" name="mileage_covered" id="mileage_covered" size="35" class="text" value="<?php echo $mileage_covered; ?>" /></td>      
    </tr>

    <tr>        
        <td align="right" bgcolor="#dbe5f1"><strong>Work to Carry:</strong></td>
        <td><textarea name="work_carry" rows="5" cols="36" class="comment" value="<?php echo $work_carry; ?>" ></textarea></td>        
    </tr>

    <tr>        
        <td align="right" bgcolor="#dbe5f1"><strong>Demages Found:</strong></td>
        <td><textarea name="demage_found" rows="5" cols="36" class="comment" value="<?php echo $demage_found; ?>" ></textarea></td>        
    </tr>

    </table>

<br>
<p style="text-align: center;"><span style="text-decoration: underline;"><strong>ACCESSORIES AVAILABLE INSIDE THE VEHICLE:</strong></span></p>

    <table width="745" align="center" border="2">

    <tr>        
        <td align="right" bgcolor="#dbe5f1"><strong>Accessories:</strong></td>
        <td><textarea name="accessories" rows="5" cols="60" class="comment-text" value="<?php echo $accessories; ?>" ></textarea></td>     
    </tr>

    <tr>
        <td><input type="reset" class="reset-button" value="CLEAR"></td>
        <td colspan="6" align="center" bgcolor="#dbe5f1" ><input type="submit" name="update" class="submit-button" value="UPDATE"></td>     
    </tr>

    </table>

</form>
</div>

</body>

</html>

What to change in the php ,if any?

Kindly help.

Hi,

you are missing a comma between these two columns, in the update statement:

work_carry = '$work_carry' demage_found = '$demage_found'

Then edit_customer_detail is not set by the form which, however, is okay if this is set by a previous step and carried through GET.

Am trying to make changes but still not display inserted data from database, Am using various techniques still nothing, any help please.

Hi @cereal, Am already found my mistake, it's just a form name as you said, Thanks for your help.

commented: Just saw, you're welcome! +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.