Mono_Pic Trust & Quality
English     Urdu

Customer address detail PHP MySQL Part 02

Friends here is 2nd parts. Here we will go ahead and make files for edit and delete customer record.

 

We change our list.php as below. We include edit and delete button.

 

list.php

 

 < ?php

include ('menue.php');        

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

echo  $delstatus =$_GET['updatestatus'];

}

?>

 < center>

 < ?php include "db.php";

 ?>

 < h2>Customer Contact List < /h2>

 < table border="1" cellpadding="8">

 < tr> < th>ID < /th> < th>Name < /th> < th>Phone < /th> < th>Email < /th> < th>Address < /th> < th>Date < /th> < th>Edit < /th> < th>Delete < /th> < /tr>

 < ?php

$result = $conn->query("SELECT * FROM customers ORDER BY id DESC");

while($row = $result->fetch_assoc()){

 ?>

   < tr>

              < td>  < ?php echo $row['id']; ?>  < /td>

             < td>  < ?php echo $row['name']; ?>  < /td>

             < td>  < ?php echo $row['phone']; ?>  < /td>

             < td>  < ?php echo $row['email']; ?>  < /td>

             < td>  < ?php echo $row['address']; ?>  < /td>

             < td>  < ?php echo $row['created_at']; ?>  < /td>

     < td> < a href="edit_list.php?editid= < ?php echo $row['id'];?>"> Edit < /td>      

     < td> < a href="delete.php?delid= < ?php echo $row['id'];?>"> Delete < /td>

     < /td>

< /tr>

   < ?php     

}

?>

 < /table>

 < /center>

< ?php

include ('footer.php');

?>

Here we create edit_list form and save it

edit_list.php

< ?php

include ('menue.php');        

include "db.php";

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

$edit_record = $_GET['editid'];

$result = $conn->query("SELECT * FROM customers where id = '$edit_record' ");

while($row = $result->fetch_assoc()){

 $cust_id=$row['id'];

$cust_name=$row['name'];

$cust_phone=$row['phone'];

$cust_email=$row['email'];

$cust_address=$row['address'];

$cust_note=$row['notes'];

$cust_date=$row['created_at'];

}}

?>

< !DOCTYPE HTML>

 < html>

 < head>

           < meta http-equiv="content-type" content="text/html" />

           < meta name="author" content="lolkittens" />

           < title>Customer < /title>

 < /head>

 < body>

 < center>

 < form action="edit_save.php" method="POST">

   < h2>Edit Customer < /h2>

   < label>Cuatomer Name < /label> < br />

   < input type="text" name="name" value=" < ?php echo $cust_name;  ?> " >  < br/> < br/>

   < label>Cuatomer Phone Number < /label> < br />

   < input type="text" name="phone" value=" < ?php echo $cust_phone;  ?>" >  < br/> < br/>

   < label>Cuatomer E-Mail < /label> < br />

   < input type="email" name="email" value=" < ?php echo $cust_email;  ?>" > < br/> < br/>

   < label>Cuatomer Address < /label> < br />

   < textarea name="address"  >  < ?php echo $cust_address;  ?>  < /textarea> < br> < br>

   < label>Note < /label> < br />

   < textarea name="notes"  >  < ?php echo $cust_note;  ?>  < /textarea> < br> < br>

   < label>Created Date < /label> < br />

   < input name="crdate" value=" < ?php echo $cust_date;  ?>" >  < br> < br>

   < input type="hidden" name="cust_id" value=" < ?php echo $cust_id;  ?>" >  < br> < br>

   < button type="submit">Save Contact < /button>

   < /form>

   < /center>

  < /body>

  < /html>

  < ?php

include ('footer.php');

?>

Here is  codes for delete record

Delete.php

 < ?php

include "db.php";

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

echo $delete_record = $_GET['delid'];

$sql = "delete from customers where id='$delete_record'";

if($conn->query($sql) === TRUE){

    $updatestatus= "Selected Customer deleted.... ";

  } else {

    $updatestatus= "Error: " . $conn->error;

  }

$conn->close();

header("location: list.php?updatestatus=$updatestatus");

}

?>

Next par we will transform our project to add show more button.