Why an I getting this message in PHP? prepare($query); $stmt->bindValue(':firstname', $firstname); $stmt->bindValue(':lastname', $lastname); $stmt->bindValue(':username', $username); $stmt->bindValue(':password', $password); $stmt->bindValue(':username', $username); $stmt->bindValue(':role', $role); $stmt = execute(); $stmt->closeCursor; } //Display Admin page include(admin_menu.php) ?> add_user_form.php Reservations Reservations Add User First Name: Last Name: Username: Password: Role: © Reservations add_user.php prepare($query); $stmt->bindValue(':firstname', $firstname); $stmt->bindValue(':lastname', $lastname); $stmt->bindValue(':username', $username); $stmt->bindValue(':password', $password); $stmt->bindValue(':username', $username); $stmt->bindValue(':role', $role); $stmt = execute(); $stmt->closeCursor; } //Display Admin page include(admin_menu.php) ?>
Why an I getting this message in PHP?
prepare($query); $stmt->bindValue(':firstname', $firstname); $stmt->bindValue(':lastname', $lastname); $stmt->bindValue(':username', $username); $stmt->bindValue(':password', $password); $stmt->bindValue(':username', $username); $stmt->bindValue(':role', $role); $stmt = execute(); $stmt->closeCursor; }
//Display Admin page include(admin_menu.php) ?>
add_user_form.php
<?php
// Initialize the session
session_start();
$firstname = $_SESSION["firstname"] = 'dale';
$lastname = $_SESSION["lastname"] = 'owens';
$username = $_SESSION["username"] = 'daleo';
$role = $_SESSION["role"] = 'A';
$adminuserid = $_SESSION["id"] = 'A';
// (Make sure the user is logged in as a valid administrator
if ($role != "A") {
header("Location: ." );
}
?>
<!DOCTYPE html>
<html>
<!-- the head section -->
<head>
<title>Reservations</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<!-- the body section -->
<body>
<header><h1>Reservations</h1></header>
<main>
<form action="add_user.php" method="post"
id="add_user_form">
<h1> Add User </h1>
<label>First Name:</label>
<input type="text" name="firstname"><br>
<label>Last Name:</label>
<input type="text" name="lastname"><br>
<label>Username:</label>
<input type="text" name="username"><br>
<label>Password:</label>
<input type="text" name="password"><br>
<label>Role:</label>
<input type="text" name="role"><br>
<label> </label>
<input type="submit" value="Add User"><br>
</form>
</main>
<footer>
<p>© <?php echo date("Y"); ?> Reservations</p>
</footer>
</body>
</html>
add_user.php
<?php
/*
server with default setting (user 'root' with no password) */
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'BN8lnGpEY9dqWsAP');
define('DB_NAME', 'id15305974_reservations');
/* Attempt to connect to MySQL database */
$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Initialize the session
session_start();
//$firstname = $_SESSION["firstname"] = 'dale';
//$lastname = $_SESSION["lastname"] = 'owens';
//$username = $_SESSION["username"] = 'daleo';
$role = $_SESSION["role"] = 'A';
$adminuserid = $_SESSION["id"] = 'A';
// (Make sure the user is logged in as a valid administrator
if ($role != 'A') {
header("Location: ." );
}
// Get the product data
$firstname = filter_input(INPUT_POST, 'firstname');
$lastname = filter_input(INPUT_POST, 'lastname');
$username = filter_input(INPUT_POST, 'username');
$password = filter_input(INPUT_POST, 'password');
$role = filter_input(INPUT_POST, 'role');
echo 'Hello';
//Validate inputs
if ($firstname == null || $firstname == false || $lastname == null || $lastname == false ||
$username == null || $username == false || $password == null || $password == fasle ||
$role == null || $role == false) {
$error = "Invalid Booking ID. Check the Booking ID and try again.";
include ('error.php');
} else {
$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME); // require a database connection
// Get reservations by date for viewing
$query = 'INSERT INTO users (firstname, lastname, username, password, role)
VALUES (:firstname,:lastname,:username,:password,:role)';
$stmt = $link->prepare($query);
$stmt->bindValue(':firstname', $firstname);
$stmt->bindValue(':lastname', $lastname);
$stmt->bindValue(':username', $username);
$stmt->bindValue(':password', $password);
$stmt->bindValue(':username', $username);
$stmt->bindValue(':role', $role);
$stmt = execute();
$stmt->closeCursor;
}
//Display Admin page
include(admin_menu.php)
?>
Step by step
Solved in 2 steps