Get value of html text field using sql query with php

تبليغ
سؤال

يرجى شرح بإيجاز لمإذا تشعر أنك ينبغي الإبلاغ عن هذا السؤال.

تبليغ
‎إلغاء

LOGINPAGE.html:
This is where the user will input their username and password. PHP method is POST.

<html>
<head>
<title>
LOG IN
</title>
<style>
body {
text-align: center;
}

</style>

</head>

<body>

<form action = “loginDatabase.php” method = “POST”>

<label>User name:</label>
<input type=”text” id=”userNameID” name=”userNameName” required>
<br />

<label>Password:</label>
<input type=”password” id=”passwordID” name=”passwordName” required>
<br />

<input type=”submit” id=”submitLoginID” name=”submitLoginName”>
</form>

</body>
</html>

LOGINDATABASE.php:
This is the processing part where the mysql query will reference the record to be displayed on ADMINPAGE.php based on the username given on LOGINPAGE.php. I cannot figure out want went wrong in line 7 since I always get an error Notice: Undefined index: userNameName in /opt/lampp/htdocs/UsersDatabaseProgram/loginDatabase.php on line 7

<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
include(‘connect.php’);

session_start();

$result = mysqli_query($con, “SELECT * FROM addUsers WHERE userName = ‘” . $_GET[‘userNameName’] . “‘”);
if ($_SERVER [“REQUEST_METHOD”] == “POST”) {

$userName = $_POST[‘userNameName’];
$password = $_POST[‘passwordName’];
/*
This doesnt work
$email = $row[’email’];
$userlevel = $row[‘userLevel’];
*/
$sql = “SELECT * FROM addUsers WHERE userName = ‘”.$userName.”‘ AND password = ‘”.$password.”‘”;

$result = mysqli_query($con, $sql);
$row = mysqli_fetch_array($result);
$count = mysqli_num_rows($result);

if ($row[“userLevel”] == “user”) {
$_SESSION[“userName”] = $userName;
header(‘location: userPage.php’);

} elseif ($row[“userLevel”] == “admin”) {

$_SESSION[“userName”] = $userName;
header(‘location: adminPage.php’);

} else {
echo “<h1> Login failed. Invalid username or password.</h1>”;

}
}

?>

ADMINPAGE.php:
This is where the name of the user, user level, and user status will be displayed.

<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
include(‘connect.php’);
include(‘loginDatabase.php’);

?>

<html>
<head>
<style>
body {
text-align: center;
}

</style>

</head>

<body>
<h2>Admin</h2>
<a href = “logOut.php”>Log-out</a> <br />
<a href = “viewRecords.php”>View records</a> <br />
<a href = “addUsers.html”>Add Record</a> <br />

<label>Welcome</label><br />
<?php echo $_SESSION[“userName”] ?>
<br />

<label>User level: </label>
<?php

while ($row = mysqli_fetch_array($result)) {
?>
<input type = “text” name = “userLevelName” value = ” <?php echo $row[‘userLevel’]; ?>”> <br />
<label>Email: </label>
<input type = “text” name = “userEmailName” value = ” <?php echo $row[’email’]; ?>”>
<?php

}

?>
<br />

</body>
</html>

‫أضف إجابة

تصفح
تصفح

مجهول يجيب