RESTURANT FORM

 CONNECTION PAGE:

<?php
$servername= "localhost";
$username= "root";
$password= "";
$db= "mwf9to12";


$conn= mysqli_connect($servername,$username,$password,$db);
?>


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>


LOGIN ACTION PAGE:

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

// catch datas

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

// echo $email, $pass;
$sql = "SELECT * FROM m4exam WHERE email='$email' AND password='$pass'";

$data=mysqli_query($conn,$sql);
$totalresponse=mysqli_num_rows($data);
$result=mysqli_fetch_assoc($data);

if($totalresponse)
{
    $_SESSION["aid"]=$result["id"];
    header("location:display.php");
}
else
{
    echo "Login failed";
}
?>


FORM INSERT 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>


FORM INSERT ACTION 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;

$sql1="SELECT * FROM m4exam WHERE email='$email'";
$data1=mysqli_query($conn,$sql1);
$res=mysqli_num_rows($data1);
if($res==0)
{
        $sql = "INSERT INTO `m4exam`(`name`, `address`, `phoneno`, `room`, `food`, `extradrink`, `table`, `payment`, `email`, `password`) VALUES ('$name','$addr','$phone','$room',    '$food','$drink','$table','$payment','$email','$pass')";
    $data= mysqli_query($conn,$sql);
    if($data)
    {
        // echo "Insert data successfully";
        header("location:login.php");   
    }
    else
    {
        echo "Not inserted";
    }
}
else
{
    echo "** email id already exits. ";
}

?>


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 m4exam WHERE id='$epid'";

$data=mysqli_query($conn,$sql);
$result= mysqli_fetch_assoc($data);

$_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>


EDIT ACTION 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 m4exam SET `name`='$name',`address`='$addr',`phoneno`='$phone',`room`='$room',`food`='$food',`extradrink`='$drink',`table`='$table',`payment`='$payment',`email`='$email' WHERE id='$epid'";
$data= mysqli_query($conn,$sql);
    if($data)
    {
        // echo "Insert data successfully";
        //header("location:login.php");
        header("location:display.php");
    }
    else
    {
        //echo "Not inserted";
        echo "Not updated";
    }

?>


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 m4exam";
$c=0;

$data= mysqli_query($conn,$sql);

?>

<!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;
     }
     a:hover{
         color: red;
         font-family:cursive ;
     }

/* other styling */
body {
  background-color: #33475b;
  color: white;
  font-family: Avenir;
  font-size: 18px;
  text-align: center;
}
::selection{
  background-color: black;
  color:#dddd2a;
}
th{
    background-color: lavenderblush; color: black;
}
    tr:nth-child(even){
        background-color: lightcoral; color: blue;
    }
    tr:nth-child(odd){
        background-color: lightsalmon; color: blue;
    }
</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= mysqli_fetch_assoc($data)){

        ?>
        <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 m4exam WHERE id='$id'";

$data=mysqli_query($conn,$sql);
if($data)
{
    header("location:display.php");
}
else
{
    echo "**Not deleted the data";
}

?>



Comments

Popular posts from this blog

Sahari

Becoming like Iron Man, a fictional superhero from the Marvel Universe

Laptop