I'm following a tutorial on youtube and I encountered a problem. Can't fix the problem since it been displaying on the textbox "Undefined Variable" after submitting.
<?php
require('./database.php');
if (isset($_POST['update'])){
$updateId = $_POST['updateId'];
$updateUsername = $_POST['updateUsername'];
$updatePassword = $_POST['updatePassword'];
$queryUpdate = "UPDATE accounts SET username = '$updateUsername', password ='$updatePassword' WHERE id = '$updateId'";
$sqlQuery = mysqli_query($connection, $queryUpdate);
echo '<script>alert("Successfully Updated!")</script>';
echo '<script>window.location.href ="/crud-tutorial/index.php"</script>';
}
if (isset($_POST['edit'])){
$editId = $_POST['editId'];
$editUsername = $_POST['editUsername'];
$editPassword = $_POST['editPassword'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>UPDATE USER</title>
<style>
html, body{
margin: 0;
padding: 0;
}
.main{
height: 100vh;
display: grid;
grid-template-rows: auto 1fr;
justify-items: center;
row-gap: 20px;
}
.main .update-main{
grid-row: 1/2;
display: grid;
grid-auto-rows: auto;
row-gap: 5px;
}
.main .update-main h3{
text-align: center;
}
</style>
</head>
<body>
<div class="main">
<form action="/crud-tutorial/update.php" method="post" class="update-main">
<h3>UPDATE USER</h3>
<input type="text" name="updateUsername" placeholder="Enter your username" value="<?php echo $editUsername?>" required>
<input type="password" name="updatePassword" required placeholder="Enter your password" value="<?php echo $editPassword?>" required>
<input type="submit" value="update" name="UPDATE">
<input type="hidden" name="updateId" value="<?php echo $editId ?>">
</form>
</div>
</body>
</html>
My index
Update file
After updating data
The error
Notice: Undefined variable: editUsername in C:xampphtdocscrud-tutorialupdate.php on line 65
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…