0

A brief intro to what I'm doing : ( If you are in a hurry just skip to the bottom. )

I'm making hotel reservation system as my university project. But it have been almost 2 day that I'm not making any progress due to this piece of code. I have done a lot of research and has change my code countless time and I don't know what else I should do to improve the following code.

"reserve table"

reserve_id int(5) Primary Key
c_id int(5)
c_username varchar(20)
r_id varchar(2)
r_name varchar(50)
checkin date
checkout date

"cust_info"

c_id int(5) Primary Key
c_name varchar(200)
c_username varchar(20)
c_password varchar(10)
c_phone int(11)
c_email varchar(30)
c_address varchar(300)

"accomodation"

r_id varchar(2) Primary Key
r_name varchar(50)
r_price int(10)
r_quantity int(2)

This is my php code

<?php

include "dbconnect.php";
include "cust_session.php";

if(isset($_POST['submit'])){

$c_username = $_POST['c_username'];
$r_id = $_POST['r_id'];
$checkin = $_POST['checkin'];
$checkout = $_POST['checkout'];

if(($c_username==null)||($r_id==null)||($checkin==null)||($checkout==null))
{

}
else
{

$try = "SELECT c.c_id, c.c_username, r.c_id, r.c_username, r.r_id, r.r_name, a.r_id, a.r_name
        FROM cust_info c JOIN reserve r
        ON c.c_username = r.c_username
        JOIN accomodation a
        ON a.r_id = r.r_id 
        WHERE r.c_username = '$c_username' and r.r_id = '$r_id'";

$result = mysqli_query($con,$try);
$data = mysqli_fetch_assoc($result);
    $c_id = $data['c_id'];
    $r_name = $data['r_name'];

$query = "INSERT INTO 'reserve' ( c_id, c_username, r_id, r_name, checkin, checkout)";
$query .= " VALUES ( '$c_id', $c_username, $r_id, '$r_name', $checkin, $checkout )";

$display_query = mysqli_query($con, $query);
  }
 }
?>

This is my "dbconnect.php"

<?php
$con = mysqli_connect('localhost' , 'root' , '' , 'pintar');

if($con){
    echo "";
} 
else{
    die("Database connection failed");
}
?>

This is my "cust_session.php"

<?php

    $mysqli = new mysqli("localhost", "root", "", "pintar");
    session_start();

    $c_username = $_SESSION['c_username'];
    $c_password = $_SESSION['c_password'];

    $sql_cust = "select * from cust_info where c_username = '$c_username' and c_password = '$c_password'";

    $result_cust = $mysqli->query($sql_cust);

    $data_cust = mysqli_fetch_assoc($result_cust);
        $c_id = $data_cust['c_id']; 
        $c_name = $data_cust['c_name'];
        $c_username = $data_cust['c_username']; 
        $c_phone = $data_cust['c_phone'];
        $c_email = $data_cust['c_email']; 
        $c_address = $data_cust['c_address'];

    $sql_room = "select * from accomodation";

    $result_room = $mysqli->query($sql_room);

    $data_room = mysqli_fetch_assoc($result_room);
        $r_id = $data_room['r_id']; 
        $r_name = $data_room['r_name'];
        $r_price = $data_room['r_price']; 
        $r_quantity = $data_room['r_quantity'];


    $sql_reserve = "select * from reserve";

    $result_reserve = $mysqli->query($sql_reserve);

    $data_reserve = mysqli_fetch_assoc($result_reserve);
        $reserve_id = $data_reserve['reserve_id'];
        $c_id = $data_reserve['c_id'];
        $c_username = $data_reserve['c_username'];
        $r_id = $data_reserve['r_id']; 
        $r_name = $data_reserve['r_name'];
        $checkin = $data_reserve['checkin'];
        $checkout = $data_reserve['checkout'];
?>

What my problem is, I'm not able to insert my reservation information into my 'reserve' database. I have check my SQL statement inside phpmyadmin and there is no problem. So my guess is that the problem is with the 'mysqli' statement . But, feel free to check the whole code.

Thank you

BTW, why cannot someone with reputation below 10 post a photo??

u_mulder
  • 54,101
  • 5
  • 48
  • 64
Adam
  • 13
  • 5

0 Answers0