Robizzle01
Limp Gawd
- Joined
- Sep 30, 2005
- Messages
- 159
I'm fairly new to php and i've never touched MySQL before today. The first thing I did was create a database and a table for user accounts. Right now, i'm trying to teach myself the basics by following some online tutorials but at the same time, I am changing them to do more what I want them to.
I'm having trouble getting arguments passed in the URL to be recognized in php, well, i'm likely just doing it wrong. Here is a sample of what I mean.
The idea is, if I just pull up list_users.php in my browser, I should (and do) get a table of all the users in the database. The table has a collumn called details with a link for each user that goes to the current page, but with ?uid=somevalue where some value is the UID of the user whom we want a full details page for. The if ($uid == "") at the top should make the page display the list of all users if no parameter is passed, but otherwise I want to go into the else { } block at the very bottom. However, even if I point my browser to list_users.php?uid=1, I still just get the generic table and the else block is never executed.
What am I doing wrong, I bet its something simple but I sure don't see it. I've been loosely following along with http://webmonkey.wired.com/webmonkey/99/21/index3a_page3.html?tw=programming
--Thanks in advance guys and gals
I'm having trouble getting arguments passed in the URL to be recognized in php, well, i'm likely just doing it wrong. Here is a sample of what I mean.
Code:
<?php
$username="username";
$password="password";
$database="database";
$db = mysql_connect("localhost", $username, $password);
@mysql_select_db($database,$db) or die("Unable to select database");
if ($uid == "")
{
printf("<h2>Listing all users from Users table</h2>\n\n");
$result = mysql_query("SELECT * FROM Users", $db);
if ($myrow = mysql_fetch_array($result))
{
echo "<table border=\"1\" cellpadding=\"5\">\n";
echo "\t<tr bgcolor=\"#dddddd\"><td>First Name</td><td>Last Name</td><td>Email</td><td>TimeOfAccountCreation</td><td>Details</td></tr>\n\n";
}
do
{
printf("\t<tr bgcolor=\"#eeeeee\"><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td><a href=\"%s\">View</a></td></tr>\n",
$myrow["FirstName"], $myrow["LastName"], $myrow["Email"], $myrow["TimeOfAccountCreation"], $PHP_SELF."?uid=".$myrow["UID"]);
} while ($myrow = mysql_fetch_array($result));
echo "</table>\n";
}
else
{
echo "displaying detailed information for user with UID == ".$uid."\n";
}
mysql_close();
?>
The idea is, if I just pull up list_users.php in my browser, I should (and do) get a table of all the users in the database. The table has a collumn called details with a link for each user that goes to the current page, but with ?uid=somevalue where some value is the UID of the user whom we want a full details page for. The if ($uid == "") at the top should make the page display the list of all users if no parameter is passed, but otherwise I want to go into the else { } block at the very bottom. However, even if I point my browser to list_users.php?uid=1, I still just get the generic table and the else block is never executed.
What am I doing wrong, I bet its something simple but I sure don't see it. I've been loosely following along with http://webmonkey.wired.com/webmonkey/99/21/index3a_page3.html?tw=programming
--Thanks in advance guys and gals