Thanks for help with a syntax problem in my previous post. I am now dealing with a larger problem with the script as a whole. I have created a page to view the records in a table. Next to each record I have placed a submit button. When pressed this should take the values of that record and submit to a form. This form is then used by the user to edit the record and submit the new data which then should update the original record in the database. I have got as far as I could but don't know what is wrong now. The script works in as much as I can view the records in the table but when I click the submit button to take me to the form to edit the record nothing happens. Literally nothing - it remains showing the table records.
This seems pretty tricky to me. I would be so grateful to anyone kind or patient enough to help me with this problem. Thankyou so much in advance. Here is the script in its entirety...
Mark.
<html><head><title>View Users</title></head>
<body>
<?php
session_start();
if (!isset($_SESSION['admin'])
|| $_SESSION['admin'] !== true)
{
header('Location: login.php');
exit;
}
$conn= mysql_connect( "localhost", "alexm", "rugby" )
or die( "Err:Conn" );
$db = mysql_select_db( "rugby_project", $conn) or die( "Err:Db" );
if (isset($_POST['submit']) && ($_POST["cmd"]=="edit" || $_POST["cmd"]=="edit")) {
$userID = $_POST["userID"];
$sql = "SELECT * FROM phone_numbers WHERE userID=$userID";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
if ($result)
{
$form ="<table width=\"227\" border=\"1\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\" bordercolor=\"#000000\">";
$form.="<tr bgcolor=\"#CCCCCC\"><td colspan=\"2\"><font size=\"1\" face=\"Verdana\"><center>";
$form.="Please enter New User Details";
$form.="</td></font>";
$form.="</tr><tr>";
$form.="<td><font size=\"2\" face=\"Verdana\"><form action=\"$self\"";
$form.=" method=\"post\">Username:</td>";
$form.="<td><input type=\"text\" name=\"userID\" value=\"{$row["userID"]}\">";
$form.="</td></tr><tr><td><font size=\"2\" face=\"Verdana\">Number:</td>";
$form.="<td><input type=\"text\" name=\"number\" value=\"{$row["number"]}\">";
$form.="</td></tr><tr><td><font size=\"2\" face=\"Verdana\">Password:</td>";
$form.="<td><input type=\"text\" name=\"password\" value=\"{$row["password"]}\">";
$form.="<tr><td colspan=\"2\"><center><input type=\"submit\" value=\"Add User\">";
$form.="</tr></table></form>";
echo($form);
echo( "<center><p><font size=\"1\" face=\"Verdana\">
<a href=\"viewdevices.php\">Back</a> |
<a href=\"control.php\">Return to Control Panel</a> |
<a href=\"logout.php\">Log out<p></a>
</body></html>" );
}
}
else
{
$sql = "select userID, number, password from phone_numbers order by userID";
$rs = mysql_query( $sql,$conn);
$self = $_SERVER['PHP_SELF'];
$rows = mysql_num_rows($rs);
echo( "<table width=\"30%\" border=\"1\" align=\"center\" cellpadding=\"4\" cellspacing=\"1\" bordercolor=\"#000000\">
<tr bgcolor=\"#CCCCCC\">
<td colspan=\"4\"><font size=\"1\" face=\"Verdana\">
<center>User View</center></font></td></tr>" );
echo( "<tr><td><font size=\"1\" face=\"Verdana\"><strong>User</td>" );
echo( "<td><font size=\"1\" face=\"Verdana\"><strong>Phone Number</td>" );
echo( "<td><font size=\"1\" face=\"Verdana\"><strong>Password</td>" );
echo( "<td><font size=\"1\" face=\"Verdana\"><i><center>Edit</td></tr>" );
if(mysql_num_rows($rs))
{
while( $row = mysql_fetch_array( $rs ) ){
echo( "<form name=\"edit\" method=\"post\" action=\"$self\">");
$userID=$row["userID"];
$number=$row["number"];
$password=$row["password"];
echo '<tr><td><font size="2" face="Verdana">' . $userID . '</td>';
echo '<td><font size="2" face="Verdana">' . $number . '</td>';
echo '<td><font size="2" face="Verdana">' . $password . '</td>';
echo '<td><center><input type="hidden" name="edit" value="' . $userID . '" /><input type="submit" name="edit" value="Edit"></form></td></tr>';
}
echo( "</table><p><table width=\"30%\" border=\"1\" align=\"center\" cellpadding=\"4\" cellspacing=\"1\" bordercolor=\"#000000\">
<tr bgcolor=\"#CCCCCC\">
<td colspan=\"2\"><font size=\"1\" face=\"Verdana\">
<center>There are $rows records in this table</center></font></td></tr></table>" );
echo' <p><font size="1" face="Verdana"><center>
<a href="javascript:history.go(-1)">Return to Control Panel</a> |
<a href="logout.php">Log out</a>
</body></html> ';
}
else
{
echo( "<table width=\"30%\" border=\"1\" align=\"center\" cellpadding=\"4\" cellspacing=\"1\" bordercolor=\"#000000\">
<tr bgcolor=\"#CCCCCC\">
<td colspan=\"2\"><font size=\"1\" face=\"Verdana\">
<center>This table has no records yet</center></font></td></tr></table>" );
}
}
?>