I'm working on a MySQL database project - all a bit out of my league, I never touched PHP before January - I barely knew of its existance. I love playing with it but I'm very much a beginner! My task is to make an interface for the database according to certain requirement specifications. I've written 14 scripts in total. But I have a problem with two of them..: one aims to perform a cross table query and the other aims to update records. I've pretty much given up hope on them - means a longer evaluation in the project unless someone has the patience to help out here? =\
Thanks for all the help up to this point from a number of people - If you don't have time to help over these I fully appreciate 🙂 I'm grateful enough for the help so far! But a bit more would be amazing =D Read on if you're interested 🙂
Mark.
So the first script - Is meant to do:
1) Display all the records in a table
2) Each record obviously takes a row - so on each row there is a corresponding submit button next to each record
3) When the submit button is clicked it should display a form
4) In each field of the form the default value should be that of the currect record
5) The user can then change the default value to what they want...
6) Click submit at the bottom of the form and thus update the record in the database
So... points 1 - 2 work so far and 3 - 6 just don't - no errors in the php.exe command prompt debug thing either. The submit button just doesn't respond as such and the script remains displaying the records for the table. Et Voila, the script is below and I'm clueless... I could be missing an integral chunk of code - I could have written some lines incorrectly - I really am clueless to what is wrong or what I can possibly do to make it work - If you need a copy of the database and the whole set of scripts to test it out yourself I can e-mail them to you - you probably don't need to though =p MANY thanks if you can fix this you're a God who should be worshipped.
<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")) {
$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=\"Update User\">";
$form.="</tr></table></form>";
echo($form);
echo( "<center><p><font size=\"1\" face=\"Verdana\">
<a href=\"viewdevices.php\">Back</a>" );
echo '<p><font size="1" face="Verdana"><center>
<a href="controladmin.php">Return to Control Panel</a> |
<a href="logout.php">Log out</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><input type="hidden" name="userID" value="' . $userID . '" /><center><input type="submit" name="cmd" value="Edit"></td></form>';
}
echo( "</tr></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="controladmin.php">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>" );
}
}
?>
I've posted the Second Problem Script Below as I maxed out of the character limit...