Mono_Pic Trust & Quality
English     Urdu

Customer address detail PHP Mysql Part 01

Customer address detail.

 

To save Customer's contact list in PHP, we need 2 parts: Form to collect data PHP + MySQL to save it in database. Here’s we have a simple working code; we can use:

Run this in cpanel with phpMyAdmin. 

 

First we need to create Database name customer_detail.

Create table in above database

CREATE TABLE customers (

  id INT(11) AUTO_INCREMENT PRIMARY KEY,

  name VARCHAR (100) NOT NULL,

  phone VARCHAR(20),

  email VARCHAR(100),

  address TEXT,

  notes TEXT,

  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP

);

 

2. db.php - Database Connection php codes

 < ?php

//db.php  table to save customer detail.

$host = "localhost";

$user = "root"; // change to cpanel db user

$pass = "";     // change to cpanel db password

$db   = "customer_detail"; // change to your db name

$conn = new mysqli($host, $user, $pass, $db);

if($conn->connect_error){

  die("Connection failed: " . $conn->connect_error);

}

?>

 

2. menue.php  Codes for top simple navigation

 

 < !DOCTYPE html>

 < html>

 < head>

 < style>

  nav {

    background: #007bff;

    padding: 15px;

    text-align: center;

  }

  nav a {

    color: white;

    text-decoration: none;

    padding: 14px 20px;

    font-size: 18px;

  }

  nav a:hover {

    background: #0056b3;

    border-radius: 5px;

  }

 < /style>

 < /head>

 < body>

 < nav>

   < a href="index.php">Home < /a>

   < a href="customer.php">Add Customer < /a>

   < a href="list.php">Customer List < /a>

   < a href="contact.php">Contact < /a>

 < /nav>

 < div style="position: absolute; left:10px; top:40px; color: blue; font-size: 30px; font-family: fantasy; ">

 < h5>Wakhrasoft.com < /h5>

 < /div>

 < /body>

 < /html>

 

 

4. index.php This is for startup system,

 

 < ?php

include ('menue.php');        

?>

 < !DOCTYPE HTML>

 < html>

 < head>

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

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

 < title> Customer list < /title>

 < /head>

 < body>

 < center>

 < br /> < br /> < br /> < br />

 < ?php

echo 'welcome customer address detail';

?>

 < /center>

 < /body>

 < /html>

 < ?php

include ('footer.php');

?>

 

5. customer.php - Add Customer data Form

 

 < ?php

include ('menue.php');

?>

 < !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="save.php" method="POST">

   < h2>Add Customer < /h2>

   < input type="text" name="name" placeholder="Customer Name" required> < br> < br>

   < input type="text" name="phone" placeholder="Phone Number"> < br> < br>

   < input type="email" name="email" placeholder="Email"> < br> < br>

   < textarea name="address" placeholder="Address"> < /textarea> < br> < br>

   < textarea name="notes" placeholder="Notes"> < /textarea> < br> < br>

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

 < /form>

 < /center>

 < /body>

 < /html>

 < ?php

include ('footer.php');  

?>

 

4. save.php – Customer’s detail Save to Database

 < ?php

include "db.php";

 

if($_SERVER["REQUEST_METHOD"] == "POST"){

  $name    = $conn->real_escape_string($_POST['name']);

  $phone   = $conn->real_escape_string($_POST['phone']);

  $email   = $conn->real_escape_string($_POST['email']);

  $address = $conn->real_escape_string($_POST['address']);

  $notes   = $conn->real_escape_string($_POST['notes']);

  $sql = "INSERT INTO customers (name, phone, email, address, notes)

          VALUES ('$name', '$phone', '$email', '$address', '$notes')";

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

   // echo "Customer saved successfully! ";

  } else {

    //echo "Error: " . $conn->error;

  }

}

$conn->close();

include "index.php";

?>

 

5. list.php - Show All Contacts

 

 < ?php

include ('menue.php');        

?>

 < 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> < /tr>

< ?php

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

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

  echo " < tr>

           < td>{$row['id']} < /td>

           < td>{$row['name']} < /td>

           < td>{$row['phone']} < /td>

           < td>{$row['email']} < /td>

           < td>{$row['address']} < /td>

           < td>{$row['created_at']} < /td>

         < /tr>";

}

?>

 < /table>

 < /center>

 < ?php

include ('footer.php');

?>

 

6. contact.php - Show All Contacts

 < ?php

include ('menue.php');        

?>

 < !DOCTYPE HTML>

 < html>

 < head>

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

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

 

           < title>Contact.php < /title>

 < /head>

 < body>

 < center>

 < br /> < br /> < br /> < br />

 < ?php

echo 'welcome customer address detail';

?>

 < /center>

 < /body>

 < /html>

 < ?php

include ('footer.php');

?>

 

7. footer.php.  It will show footer  on page bottom

 < br /> < br /> < br /> < br />

 < center>

 < br />

 

 < footer>

 < div>

 < p>

 < p>   < p>©  < span id="currentYear"> < /span> All rights reserved. | www.wakhrasoft.com < /p> < /p>

 < p>   < p> < span > < /span> admin@wakhrasoft.com < /p> < /p>

 < /p>

 < /div>

 < /footer>

 < /center>

 < br />

Next part we will add codes for Edit and update customer record.