Professional Documents
Culture Documents
Customer Crud
Customer Crud
php
<?php
include "config.php";
/*$db_host = "localhost";
$db_username = "root";
$db_passwd = "";
$conn= mysqli_connect($db_host, $db_username, $db_passwd) or die ("Could not
connect!\n");
echo "</table>\n";
mysqli_free_result($result);
mysqli_close( $conn );
?>
</body>
</html>
//update.php
<?php
include "config.php";
?>
<form method="GET" action="<?php echo "save.php"; ?>">
<pre>
Customer ID: <input type="text" name="customer_id" value="<?php echo
$_GET['cust_id'];?>">
</pre>
<?php
$result = mysqli_query( $conn,"SELECT * FROM customer where customer_id = ".
$_GET['cust_id']);
//$num_rows = mysqli_num_rows( $result );
//echo "There are currently $num_rows rows in the table<P>";
echo "<table border=1>\n";
while ($row = mysqli_fetch_array($result)) { ?>
<pre>
Title: <input type="text" name="title" value="<?php echo $row['title'];?
>"</br>
First Name: <input type="text" name="fname" value="<?php echo $row['fname'];?
>"></br>
Last Name: <input type="text" name="lname" value="<?php echo $row['lname'];?
>"></br>
Address: <input type="text" name="address" value="<?php echo
$row['addressline'];?>"></br>
Town: <input type="text" name="town" value="<?php echo $row['town'];?
>"</br>
Phone: <input type="text" name="phone" value="<?php echo $row['phone'];?
>"</br>
Zipcode: <input type="text" name="zip" value="<?php echo $row['zipcode'];?
>"</br>
<input type="submit" formaction="save.php" name="Submit" value="save"></br>
<input type="submit" formaction="edit.php" name="Submit" value="update">
</pre>
<?php }
echo "</table>\n";
echo "</form>";
mysqli_free_result($result);
mysqli_close( $conn );
?>
</body>
</html>
//save.php
<?php
include "config.php";
if ($_GET['Submit'] == "save"){
$title = $_GET['title'];
$fname = $_GET['fname'];
$lname = $_GET['lname'];
$address = $_GET['address'];
$town = $_GET['town'];
$phone = $_GET['phone'];
$zip = $_GET['zip'];
echo $title;
$sql = "INSERT INTO CUSTOMER (title,fname,lname,addressline,town,zipcode,phone)
values ('$title','$fname','$lname','$address','$town','$phone','$zip');";
echo $sql;
$result = mysqli_query( $conn,$sql);
if ($result) {
echo "customer saved";
}
}
?>
//edit.php
<?php
include "config.php";
if ($_GET['Submit'] == "update"){
$customer_id = $_GET['customer_id'];
$title = $_GET['title'];
$fname = $_GET['fname'];
$lname = $_GET['lname'];
$address = $_GET['address'];
$town = $_GET['town'];
$phone = $_GET['phone'];
$zip = $_GET['zip'];
echo $title;
$sql = "UPDATE CUSTOMER SET title = '$title',fname = '$fname',lname =
'$lname',addressline = '$address',town = '$town',zipcode = '$zip',phone = '$phone'
WHERE customer_id = " . $customer_id ;
echo $sql;
$result = mysqli_query( $conn,$sql);
if ($result) {
?>
//delete.php
<?php
include "config.php";
?>