Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Still has routing issues #311

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,15 @@
| Bryan | https://github.com/BryanTheLai |
| Yong | https://github.com/ahhyang |
| Kevin | https://github.com/kevin07212004 |
<<<<<<< Updated upstream
=======
| Edzer | https://github.com/edsaur |


## If you want to put a password for the database, youll need to change the following code:
1. view/components/config.php
3. processes/config.php
4. importDB.php
5. adminSide/config.php

>>>>>>> Stashed changes
4 changes: 2 additions & 2 deletions customerSide/CustomerReservation/reservePage.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
require_once '../config.php';
require_once 'processes/config.php';

// Start the session
session_start();
Expand Down Expand Up @@ -67,7 +67,7 @@
<div id="Search Table">
<h2 style=" color:white;">Search for Time</h2>

<form id="reservation-form" method="GET" action="availability.php"><br>
<form id="reservation-form" method="GET" action="/availability.php"><br>
<div class="form-group">
<label for="reservation_date" style="">Select Date</label><br>
<input class="form-control" type="date" id="reservation_date" name="reservation_date" required>
Expand Down
29 changes: 29 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@
define('DB_USER', 'root');
define('DB_PASS', '');

<<<<<<< Updated upstream
// Create Connection
$link = new mysqli(DB_HOST, DB_USER, DB_PASS);
=======

switch($request){
case '':
case '/':
case '/home':
require __DIR__ . '/view/home.php';
break;
>>>>>>> Stashed changes

// Check Connection
if ($link->connect_error) {
Expand All @@ -23,6 +33,7 @@
echo "Error creating database: " . $link->error . "<br>";
}

<<<<<<< Updated upstream
// Switch to using the 'restaurantdb' database
$link->select_db('restaurantdb');

Expand All @@ -45,6 +56,24 @@ function executeSQLFromFile($filename, $link) {

// Close the database connection
$link->close();
=======
// FOR WRITING REVIEWS
case '/reviews':
require __DIR__ . '/view/reviews.php';
break;
case '/write-reviews':
require __DIR__ . '/view/Customers/write-reviews.php';
break;

// For Reservations
case '/reservation':
require __DIR__ . '/customerSide/CustomerReservation/reservePage.php';
break;

case '/availability':
require __DIR__ . '/customerSide/CustomerReservation/availability.php';
break;
>>>>>>> Stashed changes
}
?>

Expand Down
133 changes: 133 additions & 0 deletions processes/database-connection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php
/*--------------------BEGINNING OF THE CONNECTION PROCESS------------------*/
//define constants for db_host, db_user, db_pass, and db_database
//adjust the values below to match your database settings
// define('DB_HOST', 'localhost');
// define('DB_USER', 'root');
// define('DB_PASS', ''); //may need to set DB_PASS as 'root'
// define('DB_DATABASE', 'restaurantdb'); //make sure to set your database
// //connect to database host
// $link = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DATABASE);
// //make sure connection is good or die
// if ($link->connect_errno)
// {
// die("Failed to connect to MySQL: (" . $link->connect_errno . ") " . $link->connect_error);
// }

require_once 'config.php';


//SELECT - used when expecting single OR multiple results
//returns an array that contains one or more associative arrays
function fetch_all($query, $params = array()) {
$data = array();
global $link;

// Prepare the statement
$statement = $link->prepare($query);

if (!$statement) {
die("Error in preparing statement: " . $link->error);
}

// Bind the parameters if there are any
if (!empty($params)) {
$types = str_repeat('s', count($params)); // Assuming all parameters are strings
$statement->bind_param($types, ...$params);
}

// Execute the query
$result = $statement->execute();

// Check if execution succeeded
if (!$result) {
die("Error in executing statement: " . $statement->error);
}

// Get the result set
$result = $statement->get_result();

// Fetch all rows as an associative array
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}

// Close the statement
$statement->close();

return $data;
}

//SELECT - used when expecting a single result
//returns an associative array
function fetch_record($query, $params = array())
{
global $link;

$statement = $link->prepare($query);

if(!$statement) {
die("Error in preparing statement: " . $link->error);
}

if (!empty($params)) {
$types = str_repeat('s', count($params)); // Assuming all parameters are strings
$statement->bind_param($types, ...$params);
}

// Execute the query
$result = $statement->execute();

// Check if execution succeeded
if (!$result) {
die("Error in executing statement: " . $statement->error);
}

// Get the result
$result = $statement->get_result();

// Fetch the record as an associative array
$record = $result->fetch_assoc();

return $record;
}

//used to run INSERT/DELETE/UPDATE, queries that don't return a value
//returns a value, the id of the most recently inserted record in your database
function run_mysql_query($query, $params = array())
{
global $link;

$statement = $link->prepare($query);

if(!$statement) {
die("Error in preparing statement: " . $link->error);
}

if (!empty($params)) {
$types = str_repeat('s', count($params)); // Assuming all parameters are strings
$statement->bind_param($types, ...$params);
}

// Execute the query
$result = $statement->execute();

// Check if execution succeeded
if (!$result) {
die("Error in executing statement: " . $statement->error);
}

// Get the last inserted ID
$last_insert_id = $link->insert_id;

return $last_insert_id;
}

//returns an escaped string. EG, the string "That's crazy!" will be returned as "That\'s crazy!"
//also helps secure your database against SQL injection
function escape_this_string($string)
{
global $link;
return $link->real_escape_string($string);
}
?>
14 changes: 14 additions & 0 deletions view/components/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php // Rememeber to change the username,password and database name to acutal values
define('DB_HOST','localhost');
define('DB_USER','root');
define('DB_PASS','');
define('DB_NAME','restaurantDB');

//Create Connection
$link = new mysqli(DB_HOST,DB_USER,DB_PASS,DB_NAME);

//Check COnnection
if($link->connect_error){ //if not Connection
die('Connection Failed'.$link->connect_error);//kills the Connection OR terminate execution
}
?>