I can’t figure out this one for the life of me.
I am making a table of users and for each user I want a “Edit Password” button and an “Delete” Button. I filled the form using a loop from my MySQL database of users. Here is my function to fill my table.
Functions.php
function fillUser()
{
$counter = 1;
$result = mysql_query("SELECT * FROM users") or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$edit[$counter] = "edit$counter";
$del[$counter] = "del$counter";
echo "<td><div align=\"center\">".$row['name']."</div></td>";
echo "<td><div align=\"center\"><input name=".$edit[$counter]." type=\"submit\" id=\"Edit\" value=\"Edit Password\">";
if($row['name'] != "Admin")
{
echo "<td><div align=\"center\"><input name=".$del[$counter]." type=\"submit\" id=\"Delete\" value=\"Delete\">";
}
echo "</tr>";
$counter++;
}
}
This works great. I then click on one of the buttons from my Edit Password category.
Edituser.php
<?php
session_start();
//include the functions file
require ("functions.php");
//config.php holds all the database setup info form when the install process was started
require("config.php");
mysql_connect("$ServerURL", "$DBUser", "$UserPass") or die(mysql_error());
mysql_select_db("$DBName") or die(mysql_error());
$counter = 1;
$result = mysql_query("SELECT * FROM users") or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$test = $_POST['edit1'];
echo $test;
$name = "edit$counter";
echo $name;
echo " ";
echo $_POST['$name'];
if($_POST['$name'])
echo "it worked";
$counter++;
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="users" method="post" action="edituser.php">
<table width="75%" border="1" align="center" bordercolor="#0000FF" id="users">
<tr>
<?fillUser(); //Make and fill the user table?>
</tr>
</table>
<div align="center"> </div>
</form>
<table width="25%" border="0" align="center">
<tr>
<td><div align="center"><a href="<?echo "$MenuLoc"?>/index.php">Main</a></div>
</td>
<td><div align="center"><a href="<?echo "$MenuLoc"?>/adduser.php">Add New
User</a></div>
</td>
</tr>
</table>
</body>
</html>
In the part up top if I put in $test = $POST['edit1']; and I click on the first button then it outputs “Edit Password” on the screen with echo $test;. When I do $name = "edit$counter"; and then echo $name; I get an output of “edit1 edit2” and so on across the screen, but when I do echo $POST['$name']; I get nothing ever. if($_POST['$name']) also dosen't work. I don’t know what I’m missing.