Forgive me if i mess this up...first time posting.
Question :
I want it to iterate through the database and then:
- assign a note
- status(radio button)
- submit button
For every user listed in table.
PBM : anytime I try to to make a change to any of the users it only updates the last user on the table and inconsistently updates the notes.
I just want it to update the 1 specific user that is in that row on the table.
If there is a more efficient or prepackaged way of doing this I am all ears. I would still like to figure out what i am doing wrong. I know that this is currently sql vulnerable code but for the sake of simplicity for me, inputs are not sanitized.
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css"
</head>
<h1>In Out Board</h1>
<?php
$conn = new mysqli('xxxx', 'xxx', 'xxx', 'xxxxx');
if ($conn->connect_error) {
die("connection failed: " . $conn->connect_error);
}
if (isset($_GET['submit'])) {
$idkey = $_GET['idkey'];
$Status = $_GET['status'];
$Notes = $_GET['notes'];
$query = "update InOutUsers set status='$Status', Notes='$Notes'where idkey='$idkey'";
$result = mysqli_query($conn, $query) or die(mysqli_error());
}
$sql = "SELECT Name, Status, Notes, idkey FROM InOutUsers";
$result = $conn->query($sql);
echo '<table><thead><form>';
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo '<tr>';
echo '<td>' . $row["Name"] . '</td>';
echo '<td>' . $row["Status"] . '</td>';
echo '<td>' . $row["Notes"] . '</td>';
echo "<input type='hidden' name='idkey' value='{$row['idkey']}' />";
echo '
<td style="width: 100px"><input type="radio" name="status" value="In" >In
<input type="radio" name="status" value="Out" >Out </td>';
echo '<td>Status: <input type="text" name="notes" placeholder="Where are you going?"></td>';
echo '<td>';
echo "<input type='submit' name='submit' value='update'/>";
echo '</td>';
echo '</tr>';
echo '<br>';
}
}
echo '</form></thead></table>';
Here is my sql:
CREATE TABLE IF NOT EXISTS `InOutUsers` (
`Name` text NOT NULL,
`Status` varchar(3) NOT NULL,
`Notes` text,
`idkey` int(11) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;
I fairly new to programming and to using stack exchange so feel free to advise me of anything that I am doing wrong. I fear its something simple but i cannot wrap my head around it.