RESTAURANT USING PDO

 CONNECTION PAGE

<?php

$servername = "localhost";
$username = "root";
$password = "";
$db="mwf9to12";

try{
    $conn = new PDO("mysql:host={$servername};dbname={$db}",$username,$password);

}catch(PDOException $e){
    echo $e->getMessage();

}//catch

?>



LOGIN PAGE:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>LOGIN ADMIN</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
  </head>

<body>
<h2 class="mx-auto w-50 mt-3 text-center">Happy Restautant</h2>
<hr class="mx-auto w-50 mt-3">
<form method="post" action="loginaction.php" class="mx-auto w-50 mt-3">
<div class="mb-3">

    <lable  class="form-label">
        Enter Email:
    </lable>
    <input type="email" name="email" class="form-control"><br>
</div>
<div class="mb-3">
    <label  class="form-label">
        Enter Password:
    </label>
     <input type="password" class="form-control" name="password"><br><br><br>
</div>

<div class="form-group text-center">
    <input type="submit" name="submit" value="LOG IN" class="btn btn-primary">&nbsp;&nbsp;&nbsp;&nbsp;

    <a href="forminsert.php" class="btn btn-primary">SIGN IN</a>
    </div>
</form><br>


</body>
</html>



LOGINACTION PAGE

<?php
session_start();
//1. connection
include("connection.php");

// catch datas

$email = $_REQUEST['email'];
$pass = md5($_REQUEST['password']);

// echo $email, $pass;
$sql = "SELECT * FROM pdoexam WHERE email=:email AND password=:pass";
$query=$conn->prepare($sql);
$query->bindparam(':email',$email);
$query->bindparam(':pass',$pass);

$data= $query->execute();

if($query->rowCount()){
    $res=$query->fetch(PDO::FETCH_ASSOC);
    $_SESSION['aid']= $res['id'];
    // echo $_SESSION['aid'];
    header("location:display.php");
}else{
    echo "**LOGIN FAILED";
}



?>



FORMINSERT PAGE

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Admin Form insert</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
</head>
<body>
<h2 class="mx-auto w-50 mt-3 text-center">Table Booking Form</h2>
<hr class="mx-auto w-50 mt-3">
<form method="post" action="forminsertaction.php" class="mx-auto w-50 mt-3 ">

<div class="form-group">
    <label> Enter Name: </label>
     <input class="form-control" type="text" name="name">
</div>
<br>
<div class="form-group">
    <label>Enter Address: </label>
     <input class="form-control" type="text" name="address">
</div>
<br>
<div class="form-group">
    <label>Enter Phone Number:</label>
     <input class="form-control" type="text" name="phone">
</div>
<br>
<div class="form-group">
    <label>Room:</label>
     <input type="radio" name="room" value="ac"> AC
     <input type="radio" name="room" value="nonac"> Non-AC
</div>
<br>
<div class="form-group">
    <label>Food:</label>
    <select name="food" class="form-control">
        <option value="">Choose Food</option>
        <option value="burgers"> Burgers</option>
        <option value="hotdogs"> Hot Dogs</option>
        <option value="sandwiches"> Sandwiches</option>
        <option value="pizza"> Pizza</option>
    </select>
</div>
<br>
<div class="form-group">
    <label>Extra drink:</label>
     <input  type="checkbox" name="drink[]" value="baileys"> Baileys
     <input  type="checkbox" name="drink[]" value="midori"> Midori
     <input  type="checkbox" name="drink[]" value="sambuca"> Sambuca
     <input  type="checkbox" name="drink[]" value="kahlua"> Kahlua
</div>
<br>
<div class="form-group">
    <label>Table:</label>
    <select name="table" class="form-control">
        <option value="">No of Persons</option>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="6">6</option>
    </select>
</div>
<br>
<div class="form-group">
    <label>Payment:</label>
     <input  type="radio" name="payment" value="online"> Online
     <input  type="radio" name="payment" value="offline"> Offline
</div>
<br>
<div class="form-group">
    <label>Enter Email: </label>
     <input class="form-control" type="email" name="email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$">
</div>
<br>

<div class="form-group">
    <label>    Enter Password: </label>
     <input class="form-control" type="password" name="password"><br>
</div>
    <br>
    <div class="form-group text-center">
     <input type="submit" name="submit" value="SUBMIT" class="btn btn-primary">
     <input type="reset" name="reset" value="RESET" class="btn btn-primary">
    </div>
</form><br><br>
</body>
</html>


FORMINSERTACTION PAGE:

<?php

include("connection.php");

$name = $_REQUEST["name"];
$addr = $_REQUEST["address"];
$phone = $_REQUEST["phone"];
$room =$_REQUEST["room"];
$food =$_REQUEST["food"];
$drink = implode(",",$_REQUEST['drink']);
$table = $_REQUEST["table"];
$payment = $_REQUEST["payment"];

$email = $_REQUEST["email"];
$pass = md5($_REQUEST["password"]);

// echo $room, $food, $drink, $table, $payment;


$sql = "INSERT INTO `pdoexam`(`name`, `address`, `phoneno`, `room`, `food`, `extradrink`, `table`, `payment`, `email`, `password`) VALUES (:name,:addr,:phone,:room,:food,:drink,:table,:payment,:email,:pass)";

$query = $conn->prepare($sql);

$query->bindparam(':name',$name);
$query->bindparam(':addr',$addr);
$query->bindparam(':phone',$phone);
$query->bindparam(':room',$room);
$query->bindparam(':food',$food);
$query->bindparam(':drink',$drink);
$query->bindparam(':table',$table);
$query->bindparam(':payment',$payment);
$query->bindparam(':email',$email);
$query->bindparam(':pass',$pass);


if($query->execute()){
    header("location:login.php");
}//if
else{
    echo "Error must be Occured";
}//else

?>


EDIT PAGE:

<?php
session_start();
include 'connection.php';

if(!isset($_SESSION["aid"])){
    echo "<script>alert('please login first')</script>";
    echo "<script>window.location.href='login.php'</script>";
}

$epid= $_REQUEST['ep'];

$sql = "SELECT * FROM pdoexam WHERE id=:epid";
$query = $conn->prepare($sql);
$query->bindparam(':epid',$epid);
$data = $query->execute();

$result = $query->fetch(PDO::FETCH_ASSOC);


$_SESSION['epid'] = $epid;

?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>
        DISPLAY ADMIN PORTAL
    </title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
</head>       
<body>
    <h2 class="mx-auto w-50 mt-3 text-center">Table Editing Form
</h2>
<hr class="mx-auto w-50 mt-3">
<form method="post" action="formeditaction.php" class="mx-auto w-50 mt-3">

<div class="form-group">
    <label> Enter Name: </label>
     <input class="form-control" type="text" name="name" value="<?php echo $result['name']; ?>">
</div>
<br>
<div class="form-group">
    <label>Enter Address: </label>
     <input class="form-control" type="text" name="address" value="<?php echo $result['address']; ?>">
</div>
<br>
<div class="form-group">
    <label>Enter Phone Number:</label>
     <input class="form-control" type="text" name="phone" value="<?php echo $result['phoneno']; ?>">
</div>
<br>
<div class="form-group">
    <label>Room:</label>
     <input type="radio" name="room" value="ac" <?php if($result['room']=='ac'){echo "checked";}?>> AC
     <input type="radio" name="room" value="nonac" <?php if($result['room']=='nonac'){echo "checked";}?>> Non-AC
</div>
<br>
<div class="form-group">
    <label>Food:</label>
    <select name="food" class="form-control">
        <option value="">Choose Food</option>
        <option value="burgers" <?php  if($result['food']=='burgers'){echo "selected";} ?>> Burgers</option>
        <option value="hotdogs"<?php  if($result['food']=='hotdogs'){echo "selected";} ?>> Hot Dogs</option>
        <option value="sandwiches" <?php  if($result['food']=='sandwiches'){echo "selected";} ?>> Sandwiches</option>
        <option value="pizza" <?php  if($result['food']=='pizza'){echo "selected";} ?>> Pizza</option>
    </select>
</div>
<br>
<div class="form-group">
    <?php
$drinkArray=explode(",",$result['extradrink']);
?>
    <label>Extra drink:</label>
     <input  type="checkbox" name="drink[]" value="baileys" <?php if(in_array("baileys",$drinkArray)){echo "checked";} ?>> Baileys
     <input  type="checkbox" name="drink[]" value="midori" <?php if(in_array("midori",$drinkArray)){echo "checked";} ?>> Midori
     <input  type="checkbox" name="drink[]" value="sambuca" <?php if(in_array("sambuca",$drinkArray)){echo "checked";} ?>> Sambuca
     <input  type="checkbox" name="drink[]" value="kahlua" <?php if(in_array("kahlua",$drinkArray)){echo "checked";} ?>> Kahlua
</div>
<br>
<div class="form-group">
    <label>Table:</label>
    <select name="table" class="form-control">
        <option value="">No of Persons</option>
        <option value="1" <?php  if($result['table']=='1'){echo "selected";} ?>>1</option>
        <option value="2" <?php  if($result['table']=='2'){echo "selected";} ?>>2</option>
        <option value="3" <?php  if($result['table']=='3'){echo "selected";} ?>>3</option>
        <option value="4" <?php  if($result['table']=='4'){echo "selected";} ?>>4</option>
        <option value="6" <?php  if($result['table']=='6'){echo "selected";} ?>>6</option>
    </select>
</div>
<br>
<div class="form-group">
    <label>Payment:</label>
     <input  type="radio" name="payment" value="online" <?php if($result['payment']=='online'){echo "checked";}?>> Online
     <input  type="radio" name="payment" value="offline" <?php if($result['payment']=='offline'){echo "checked";}?>> Offline
</div>
<br>
<div class="form-group">
    <label>Enter Email: </label>
     <input class="form-control" type="email" name="email" value="<?php echo $result['email']; ?>" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$">
</div>
<br>

<div class="form-group text-center">
     <input type="submit" name="submit" value="SUBMIT" class="btn btn-primary">
    </div>
</form><br><br>
</body>
</html>


EDITACTION PAGE

<?php


session_start();
include 'connection.php';

if(!isset($_SESSION["aid"])){
    echo "<script>alert('please login first')</script>";
    echo "<script>window.location.href='login.php'</script>";
}

$epid=$_SESSION['epid'];

$name = $_REQUEST["name"];
$addr = $_REQUEST["address"];
$phone = $_REQUEST["phone"];
$room =$_REQUEST["room"];
$food =$_REQUEST["food"];
$drink = implode(",",$_REQUEST['drink']);
$table = $_REQUEST["table"];
$payment = $_REQUEST["payment"];

$email = $_REQUEST["email"];
$pass = md5($_REQUEST["password"]);


$sql = "UPDATE pdoexam SET `name`=:name,`address`=:addr,`phoneno`=:phone,`room`=:room,`food`=:food,`extradrink`=:drink,`table`=:table,`payment`=:payment,`email`=:email WHERE id=:epid";

$query= $conn->prepare($sql);

$query->bindparam(':name',$name);
$query->bindparam(':addr',$addr);
$query->bindparam(':phone',$phone);
$query->bindparam(':room',$room);
$query->bindparam(':food',$food);
$query->bindparam(':drink',$drink);
$query->bindparam(':table',$table);
$query->bindparam(':payment',$payment);
$query->bindparam(':email',$email);
$query->bindparam(':epid',$epid);

if($query->execute()){
    header("location:display.php");
}else{
    echo "Error cases";
}//else

?>


DISPLAY PAGE:

<?php
// echo "DISPLAY PAGE";
session_start();
include 'connection.php';
if(!isset($_SESSION["aid"])){
    echo "<script>alert('please login first')</script>";
    echo "<script>window.location.href='login.php'</script>";
}
$id=$_SESSION['aid'];

$sql = "SELECT * FROM pdoexam";
    
    $query=$conn->prepare($sql);   
    $data= $query->execute();
    $c=0;
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>
        DISPLAY ADMIN PORTAL
    </title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
</head>       
<style type="text/css">
    
    a{
        color:  yellowgreen;
        text-decoration: none;
     }

/* other styling */
body {
  background-color: #33475b;
  color: white;
  font-family: Avenir;
 
}
::selection{
  background-color: black;
  color:#dddd2a;
}
</style>
<body>
<h2 class="mx-auto w-50 mt-3 text-center">Happy Restautant
</h2>
<hr class="mx-auto w-50 mt-3">
    <table border="1" width="100%">
        <tr>
            <th>Sr No</th>
            <th>NAME</th>
            <th>ADDRESS</th>
            <th>PHONE</th>
            <th>ROOM</th>
            <th>FOOD</th>
            <th>EXTRA DRINK</th>
            <th>TABLE</th>
            <th>PAYMENT</th>       
            <th>EMAIL</th>
            <th>ACTIONS</th>
        </tr>
        <?php

        while($res = $query->fetch(PDO::FETCH_ASSOC)){

        ?>
        <tr>
            <td><?php echo ++$c; ?></td>
            <td><?php echo $res['name']; ?></td>
            <td><?php echo $res['address']; ?></td>
            <td><?php echo $res['phoneno']; ?></td>
            <td><?php echo $res['room']; ?></td>
            <td><?php echo $res['food']; ?></td>
            <td><?php echo $res['extradrink']; ?></td>
            <td><?php echo $res['table']; ?></td>
            <td><?php echo $res['payment']; ?></td>
            <td><?php echo $res['email']; ?></td>
           
            <td>
                <a href="edit.php?ep=<?php echo $res['id'] ?>">EDIT</a>
                <a href="delete.php?del=<?php echo $res['id'] ?>">DELETE</a>               
            </td>

        </tr>
        <?php
                }
        ?>

    </table><br>
    
</body>
</html>



DELETE PAGE:

<?php

session_start();
include 'connection.php';

if(!isset($_SESSION["aid"])){
    echo "<script>alert('please login first')</script>";
    echo "<script>window.location.href='login.php'</script>";
}

$id=$_REQUEST["del"];

$sql = "DELETE FROM pdoexam WHERE id=:id";

$query = $conn->prepare($sql);

$query->bindparam(':id',$id);

if($query->execute()){
    header("location:display.php");
}else{
    echo "Not deleted";
}

?>


PDOEXAM.SQL

-- phpMyAdmin SQL Dump
-- version 5.2.0
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Jul 15, 2022 at 07:29 AM
-- Server version: 10.4.24-MariaDB
-- PHP Version: 8.1.6

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `mwf9to12`
--

-- --------------------------------------------------------

--
-- Table structure for table `pdoexam`
--

CREATE TABLE `pdoexam` (
  `id` int(11) NOT NULL,
  `name` varchar(200) NOT NULL,
  `address` varchar(255) NOT NULL,
  `phoneno` bigint(255) NOT NULL,
  `room` varchar(200) NOT NULL,
  `food` varchar(200) NOT NULL,
  `extradrink` varchar(255) NOT NULL,
  `table` varchar(255) NOT NULL,
  `payment` varchar(200) NOT NULL,
  `email` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Dumping data for table `pdoexam`
--

INSERT INTO `pdoexam` (`id`, `name`, `address`, `phoneno`, `room`, `food`, `extradrink`, `table`, `payment`, `email`, `password`) VALUES
(1, 'Wade Lindsey', 'Aliqua Voluptate la', 8911342295, 'ac', 'hotdogs', 'midori,kahlua', '3', 'offline', 'saif@s.com', 'c20ad4d76fe97759aa27a0c99bff6710'),
(3, 'Ahmed sk', 'burdwan', 1212122112, 'nonac', 'burgers', 'baileys,sambuca,kahlua', '6', 'online', 'ryqihyveg@mailinator.com', 'd41d8cd98f00b204e9800998ecf8427e');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `pdoexam`
--
ALTER TABLE `pdoexam`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `pdoexam`
--
ALTER TABLE `pdoexam`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;



Comments

Popular posts from this blog

Sahari

[[ ROYAL CAR ]] CHANGE PASSWORD - DYNAMIC BANNER - MULTIPLE IMAGE - LOGIN LOGOUT BACK BUTTON MIDDLEWARE STOP - MAIL DIRECTLY WITH FEEDBACK WITH SAVE IN SQL DB - ADMIN REPLY EXISTING MAILS - DYNAMICALLY CSS CHANGE

Linux Terminal