I'm wanting to allow my user to edit rows in the database. I'm following along on a tutorial and i can't seem to get it working. I'm at a lost as i have no idea why my variables aren't being declared when i clearly have (in my head).
<?php
// including the database connection file
include_once("connect.php");
if(isset($_POST['update']))
{
$StaffID = $_POST["StaffID"];
$Name=$_POST["Name"];
$Address=$_POST['Address'];
$Telephone=$_POST['Telephone'];
$BusinessID=$_POST['BusinessID'];
$result = mysqli_query($conn, "UPDATE staff SET Name='{$Name}',Address='{$Address}',Telephone='{$Telephone}', BusinessID='{$BusinessID}' WHERE StaffID = $StaffID");
//redirectig to the display page. In our case, it is index.php
header("Location: HomePHP.php");
}
}
?>
<?php
//getting id from url
$StaffID = $_GET['StaffID']; //this is what is giving me the error even though it is exactly how it appears in my database
//selecting data associated with this particular id
$result = mysqli_query($conn, "SELECT * FROM staff WHERE StaffID=$StaffID");
while($res = mysqli_fetch_array($result))
{
$Name = $res['Name'];
$Address = $res['Address'];
$Telephone = $res['Telephone'];
$BusinessID = $res['BusinessID'];
}
?>
<html>
<head>
<title>Edit Data</title>
</head>
<body>
<a href="select.php">Home</a>
<br/><br/>
<form name="form1" method="post" action="select.php">
<table border="0">
<tr>
<td>Name</td>
<td><input type="text" name="name" value="<?php echo $Name;?>"></td>
</tr>
<tr>
<td>Age</td>
<td><input type="text" name="age" value="<?php echo $Address;?>"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" value="<?php echo $Telephone;?>"></td>
</tr>
<tr>
<td>BusinessID</td>
<td><input type="text" name="email" value="<?php echo $BusinessID;?>"></td>
</tr>
<tr>
<td><input type="hidden" name="id" value=<?php echo $_GET['StaffID'];?>></td>
<td><input type="submit" name="update" value="Update"></td>
</tr>
</table>
</form>
</body>
</html>