diff --git a/README.md b/README.md index cf873f66..a773f999 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/customerSide/CustomerReservation/reservePage.php b/customerSide/CustomerReservation/reservePage.php index 8ffc7930..f7e01cdd 100644 --- a/customerSide/CustomerReservation/reservePage.php +++ b/customerSide/CustomerReservation/reservePage.php @@ -1,5 +1,5 @@

Search for Time

-

+

diff --git a/index.php b/index.php index edb94f4d..854b04ce 100644 --- a/index.php +++ b/index.php @@ -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) { @@ -23,6 +33,7 @@ echo "Error creating database: " . $link->error . "
"; } +<<<<<<< Updated upstream // Switch to using the 'restaurantdb' database $link->select_db('restaurantdb'); @@ -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 } ?> diff --git a/processes/database-connection.php b/processes/database-connection.php new file mode 100644 index 00000000..923df3f7 --- /dev/null +++ b/processes/database-connection.php @@ -0,0 +1,133 @@ +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); +} +?> \ No newline at end of file diff --git a/view/components/config.php b/view/components/config.php new file mode 100644 index 00000000..d3ca29ab --- /dev/null +++ b/view/components/config.php @@ -0,0 +1,14 @@ +connect_error){ //if not Connection +die('Connection Failed'.$link->connect_error);//kills the Connection OR terminate execution +} +?>