rahulpatel
Programmer
I'm making a membership site where none logged in users can view members details but obviously can't update them. I've basically try using the 'Beginning PHP' example by Wrox. It does all but one thing. My members are updated on the main page when another user registers. When I click the member link it is supposed to pull the details from the database according to which link I clicked on the first page. However, all I get is the first member in the list.
Page which should receive and include the info
Any pointers would be gratefully taken onboard.
TIA.
Code:
<?php
require('config.php');
$conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS)
or die('Could not connect to MySQL database. ' . mysql_error());
mysql_select_db(SQL_DB, $conn);
?>
<html>
<head>
<title>My Title</title>
</head>
<body>
<?php
$sql = "SELECT username " .
"FROM user_info";
$result = mysql_query($sql)
or die(mysql_error());
if (mysql_num_rows($result) > 0) {
$table = "<table border=\"0\" cellpadding=\"5\">";
$table .= "<tr bgcolor=\"#FFCCCC\"><th>";
$table .= "<a href=\"" . $_SERVER['PHP_SELF'] . "?o=1\">Member</a>";
$table .= "</th></tr>";
// build each table row
$bg = '';
while ($row = mysql_fetch_array($result)) {
$bg = ($bg=='F2F2FF'?'E2E2F2':'F2F2FF');
$table .= "<tr bgcolor=\"#" . $bg . "\">" .
"<td><a href=\"charedit.php?c=" . $row['username'] . "\">" .
$row['username']. "</a></td></tr>";
}
}
echo $table;
?>
<br />
</body>
</html>
Page which should receive and include the info
Code:
<?php
require('config.php');
if (!isset($_GET['c']) || $_GET['c'] == '' || !is_numeric($_GET['c'])) {
$char='0';
} else {
$char = $_GET['c'];
}
$conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS)
or die('Could not connect to MySQL database. ' . mysql_error());
mysql_select_db(SQL_DB, $conn);
$sql = "SELECT * FROM user_info WHERE username = $char";
$result = mysql_query($sql)
or die(mysql_error());
$row = mysql_fetch_array($result);
?>
</p>
<table width="322" border="0">
<tr>
<td width="158"><strong>First Name: </strong></td>
<td width="102"><?php echo $row['first_name']; ?></td>
</tr>
<tr>
<td><strong>Last Name: </strong></td>
<td><?php echo $row['last_name']; ?></td>
</tr>
<tr>
<td><strong>City: </strong></td>
<td><?php echo $row['city']; ?></td>
</tr>
<tr>
<td><strong>State: </strong></td>
<td><?php echo $row['state']; ?></td>
</tr>
<tr>
<td><strong>Email: </strong></td>
<td><?php echo $row['email']; ?></td>
</tr>
<tr>
<td><strong>Hobbies/Interests: </strong></td>
<td><?php echo $row['hobbies']; ?></td>
</tr>
<tr>
<td><strong>Tryout:</strong></td>
<td><?php echo $row['tryout']; ?></td>
</tr>
<tr>
<td valign="top"><strong>About: </strong></td>
<td><?php echo $row['about'];?></td>
</tr>
</table>
</body>
</html>
Any pointers would be gratefully taken onboard.
TIA.