Hi guys,
Hopefuly I've got most of this code right, I think I do anyway...
What I'm trying to do here is present all known members of a DB in a table, with a 'href' $_GET included that pulls that record from the DB and injects it into the subsequent form for editing. Basically a membership DB, and this page is to update a record. If anyone knows of a different approach... I'm all ears! :p
So far my code works to the point of the $_GET. The code doesn't seem to recognise any input from a click on the link provided with address line query.
I also had an if(!isset there to check that $_GET had been set and suppress the 'Undefined Index' msg, but took it out when I was looking for the break-down. Just let me know if it is needed, I'll put it back.
I've also thrown a 'echo "Selection = " .$edit;' in there just before the form to tell me what name I have clicked on - if any; and that just shows 'Resource id #4' and continues to do so, no matter what state the page is in or what record I've clicked on :s.
I'm confused to the point of frustration.... any help would be appreciated.
Am I using the correct referrers from the query in my php? Am I substituting them correctly for php to use them as variables? Can I use 'edit' in both my $_GET['edit'] line and as a php variable '$edit' without a conflict?
These are the questions bouncing around in my head... and making it hurt :queasy:
Ta
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>AllStars - Edit User</title>
<STYLE TYPE="text/css">
<!--
TD{font-family: Tahoma; font-size: 12pt;}
TH{font-family: Tahoma; font-size: 12pt;}
a { text-decoration:none }
--->
</STYLE>
</head>
<body>
<?php
session_start();
$_GET['edit']=NULL;
// Connects to your Database
mysql_connect("localhost", "login", "password") or die(mysql_error());
mysql_select_db("MY_DB") or die(mysql_error());
if(!isset($_SESSION['status'])) {
//session_regenerate_id();
$_SESSION['status']=NULL;
echo "<p align='center'> </p>";
echo "<p align='center'> </p>";
echo "<p align='center'> </p>";
echo "<p align='center'> </p>";
echo "<p align='center'><a href='main.php'><img border='0' src='star_logo.jpg' width='284' height='292'></a></p>";
echo "<p align='center'><font face='Tahoma' size='6'>You are not Logged in. Please <a href='index.php'>Login</a></font></p>";
echo "Session = ".$_SESSION['status'];
die();
}
else
if ($_SESSION['status'] !='admin')
{
echo "<p align='center'> </p>";
echo "<p align='center'> </p>";
echo "<p align='center'> </p>";
echo "<p align='center'> </p>";
echo "<p align='center'><a href='main.php'><img border='0' src='star_logo.jpg' width='284' height='292'></a></p>";
echo "<p align='center'><font face='Tahoma' size='6'>You are not Admin.</p> <p align='center'> Return to <a href='main.php'>Main</a>, or Please <a href='index.php'>Login</a></font></p>";
echo "Session = ".$_SESSION['status'];
die();
}
else
$check = mysql_query("SELECT * FROM users")
or die(mysql_error());
echo "<p align='center'> </p>";
echo "<p align='center'> </p>";
echo "<table border='1' align='center'>";
echo "<tr><th width='60' align='center'>Login</th>";
echo "<th width='120' align='center'>Username</th>";
echo "<th width='70' align='center'>Status</th></tr>";
while($users = mysql_fetch_array( $check )){
$username = $users['username'];
echo "<tr><td align='center'>";
echo "<a href='$username'>$username</a>";
echo "</td><td>";
echo $users['name_f'] . " " . $users['name_l'];
echo "</td><td>";
echo $users['status'];
echo "</td><td width='50' align='center'>";
echo "<a href='/edit_users.php?edit=$username';>Edit</a>";
echo "</td></tr>";
}
echo "</table>";
$user=$_GET['edit'];
$edit=mysql_query("SELECT * FROM users WHERE username ='$user'")
or die(mysql_error());
echo "Selection = " .$edit;
echo "<form action=".$_SERVER['PHP_SELF']." method='post'>";
echo "<DIV ALIGN='center'>";
echo "<table border='0' cellpadding='0' cellspacing='0' width='50%' id='AutoNumber1' height='185'><tr>";
echo "<td width='64%' align='right' height='35'><font face='Tahoma'><b><font size='4'>Username: </font></b><input type='text' name='username' tabindex=1 maxlength='10' size='20' value= " .$edit['username']. "></td>";
echo "<td width='36%' align='left' height='35'><input TYPE='radio' NAME='status' tabindex=4 CHECKED value='active'><b><font face='Tahoma' size='4'>Active</b></td></tr>";
echo "<tr><td width='64%' align='right' height='35'><font face='Tahoma'><b><font size='4'>First Name: </b><input type='text' name='name_f' tabindex=2 maxlength='10' size='20' value= " .$edit['name_f']. "></td>";
echo "<td width='36%' align='left' height='35'><input TYPE='radio' NAME='status' value='admin'><font face='Tahoma' size='4'><b>Admin</b></td></tr>";
echo "<tr><td width='64%' align='right' height='35'><font face='Tahoma'><b><font size='4'>Last Name: </b><input type='text' name='name_l' tabindex=3 maxlength='10' size='20' value= " .$edit['name_l']. "></td>";
echo "<td width='36%' align='left' height='35'><input TYPE='radio' NAME='status' value='inactive'><font face='Tahoma' size='4'><b>Inactive</b></td></tr>";
echo "<tr><td width='64%' align='right' height='35'><font face='Tahoma'><b><font size='4'>Address 1: </b><input type='text' name='address1' tabindex=3 maxlength='10' size='20' value= " .$edit['address1']. "></td></tr>";
echo "<tr><td width='64%' align='right' height='35'><font face='Tahoma'><b><font size='4'>Address 2: </b><input type='text' name='address2' tabindex=3 maxlength='10' size='20' value= " .$edit['address2']. "></td></tr>";
echo "<tr><td width='64%' align='right' height='35'><font face='Tahoma'><b><font size='4'>Home Phone: </b><input type='text' name='h_phone' tabindex=3 maxlength='10' size='20' value= " .$edit['h_phone']. "></td>";
echo "<td width='64%' align='right' height='35'><font face='Tahoma'><b><font size='4'>Mobile Phone: </b><input type='text' name='m_phone' tabindex=3 maxlength='10' size='20' value= " .$edit['m_phone']. "></td>";
echo "<tr><td width='64%' align='right' height='50'></td>";
echo "<td width='36%' height='50'><font face='Tahoma'><input type='submit' name='submit' tabindex=5 value='Update'></td></tr>";
echo "</table>";
echo "</DIV>";
echo "</form>";
die();
{
echo "<p align='center'><font face='Tahoma' size='6'>Please make a selection</font></p>";
die('No Selection');
}
?>
</body
</html>