Passing variables from 1 php to another php page
Posted: Fri Feb 13, 2004 9:16 am
Hi,
Can someone help me on this problem please, I have the following php page which displays users from the database. Users are displayed in a table that containes radio buttons for each displayed users. if i select one user using the radio button and click on view or edit or delete button it should open e.g view.php with the selected user. In order to do this I tried to pass the variables using sessions but still have problems,
Can you help me please, here are displayuser.php and viewuser,php
displayuser.php
Can someone help me on this problem please, I have the following php page which displays users from the database. Users are displayed in a table that containes radio buttons for each displayed users. if i select one user using the radio button and click on view or edit or delete button it should open e.g view.php with the selected user. In order to do this I tried to pass the variables using sessions but still have problems,
Can you help me please, here are displayuser.php and viewuser,php
displayuser.php
Code: Select all
<?php
<?php
print "<form action='viewuser.php' method='POST'>";
mysql_connect("localhost") or die ("Unable to connect to databse.");
mysql_select_db("users") or die ("Unable to select database.");
$resultID = mysql_query("SELECT user_id, full_name, login_name, email, disabled FROM users");
$_SESSION['user_id'];
print "<table border=1><tr><td>edit/delete</th><th>User ID</th>";
print "<th>Full Name</th><th>Login Name</th><th>Email Address</th><th>Is user disabled ?</th>";
while ($row = mysql_fetch_row($resultID))
{
print "<tr>";
// the user-id is the first field?
echo '<td><input type="radio" name="user_id" value="', $row[0], '"/></td>';
foreach ($row as $field)
{
print "<td>$field</td>";
}
print "</tr>";
}
print "</table>";
?>
<?
print "<table>";
print "<tr>";
print "<td>";
print "<INPUT type='submit' name='View User' value='view_user'> </td>
";
print "</form>";
?>
</body>
</html>
//viewuser.php
<?php
session_start();
header("Cache-control: private"); //IE 6 Fix
?>
<?php
// Open the database connection
$dbc = mysql_connect("localhost") or die ("Unable to connect to databse.");
//select database
$dbselect = mysql_select_db("Users",$dbc) or die ("Unable to select database.");
if (!$_SESSION['user_id']) {
echo "No user selected please make a selection";
}
else {
$query = mysql_query("SELECT * FROM users WHERE user_id = $user_id");
print "<h1>'$fullname' Details" ;
}
?>
</body>
</html>
?>