Example #1
0
?>

<?php 
require_once "menu.php";
?>

<?php 
require_once "functions.php";
require_once "edit_functions.php";
if (isset($_POST["update"])) {
    updateCars($_POST["id"], $_POST["year"], $_POST["make"], $_POST["model"], $_POST["horsepower"], $_POST["topspeed"], $_POST["transmission"]);
}
if (isset($_GET["delete"])) {
    deleteCars($_GET["delete"]);
}
$car_list = getCarsData();
?>

<table border=1 >
	<tr>
		<th>id</th>
		<th>User ID</th>
		<th>Year</th>
		<th>Make</th>
		<th>Model</th>
		<th>Horsepower</th>
		<th>Topspeed</th>
		<th>Transmission</th>
		<th>X</th>
		<th>edit</th>
	</tr>
    $stmt->execute();
    $array = array();
    while ($stmt->fetch()) {
        $cars = new StdClass();
        $cars->id = $id;
        $cars->year = $year;
        $cars->user_id = $user_id;
        $cars->make = $make;
        $cars->model = $model;
        $cars->horsepower = $horsepower;
        $cars->topspeed = $topspeed;
        $cars->transmission = $transmission;
        array_push($array, $cars);
    }
    $stmt->close();
    $mysqli->close();
    return $array;
}
function deleteCars($id_to_be_deleted)
{
    $mysqli = new mysqli($GLOBALS["servername"], $GLOBALS["server_username"], $GLOBALS["server_password"], $GLOBALS["database"]);
    $stmt = $mysqli->prepare("UPDATE CarData SET deleted=NOW() WHERE id=?");
    $stmt->bind_param("i", $id_to_be_deleted);
    if ($stmt->execute()) {
        header("Location: table.php");
    }
    $stmt->close();
    $mysqli->close();
}
getCarsData();