Hi, I am trying to make an admin page for the admin to update information for users. Eventually, I want to be able to update the SAME field (like, "hair color" -- just an example) for each user at one time on one screen. The code I am posting here is a little different. This code actually draws up all of the fields for all of the users at once. Then you have the choice of whether to update a field. (In this code, since I am trying to get it working, there is only one item being written into the database.)
The trouble is: instead of writing something new into the database, it just erases the old information. So... you could say the UPDATE is working, but it is not putting the new information in there.
Actually, I was thinking the foreach part was working, but that the variable wasn't being assigned correctly.
Finally, if you see an easier way to do this using some more efficient code, suggestions are welcome.
(Sorry for the formatting in the code below. Hope you can see the meat of it without trouble.)
<?php
if(isset($_POST['submit'])) {
foreach($_POST['changed'] as $index_id) {
$title = $_POST['this_title_$index_id'];
$query = ("UPDATE user_info SET this_title='$title' WHERE index_id='$index_id'");
$now = mysql_query($query);
}
}
$mysql = mysql_query("select * from user_info");
echo "<table><form method=post action=". $_SERVER['PHP_SELF'] . " name=updateform>";
while($data = mysql_fetch_assoc($mysql)) {
echo "<tr><td colspan=2>Record" . $data['index_id'] . "</td></tr>";
//using foreach, list all the data that was returned in the $data array from mysql_fetch_assoc
foreach($data as $key => $value) {
echo "<tr><td bgcolor=yellow>" . $key . "</td><td><input name=" . $key . "_" . $data[index_id] . " type=text></td></tr>";
}
echo "<tr><td colspan=2 bgcolor=C0C0C0>Update this record? <input type=checkbox value=" . $data[index_id] ." name=changed[]></td></tr>";
}
echo "<tr><td colspan=2><input type=submit name=submit value=Submit></td></tr></form></table>";
?>