Jump to content

Need Drop down menu to display information based on username


phunnydoode

Recommended Posts

Hello my problem here is to have a drop down menu which gathers usernames from the database. Then with a click of a button the information for that specific user selected is shown. I'm close code wise but right now it's just showing me all users. I'm displaying the info in text box's to allow an admin to change the info. 

<form action="edit.php" method="post">

	 <select name="username" id="username">
	 	  <?php 
	  
 // Connects to your Database 
  $con=mysqli_connect('localhost', 'root', '');

/* check connection */

if (mysqli_connect_errno($con)) {
    trigger_error('Database connection failed: '  . mysqli_connect_error(), E_USER_ERROR);
}

$query = "SELECT `username` FROM `bencobricks` . `users`";

$result = mysqli_query($con, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($con), E_USER_ERROR);

if($result) {
	while($row = mysqli_fetch_assoc($result)) {
		//printf ("%s\n %s\n ",
		echo	"<label for='username'>Username: </label> <option value='$row[username]'>$row[username] </option><br/>";
			
		echo "<br/><br/> ";
		
	}
} 

mysqli_close($con);

?>
	 </select>
<br />
  <input name="send" id="send" type="submit" value="Edit User" />
</form>

Then in the edit.php file i have this code: 

<?php 

// Connects to your Database
$con=mysqli_connect('localhost', 'root', '');

/* check connection */

if (mysqli_connect_errno($con)) {
	trigger_error('Database connection failed: '  . mysqli_connect_error(), E_USER_ERROR);
}

if (isset($_POST['send'])) {
 $username = $_POST['username'];
 
 $query = "SELECT * FROM `bencobricks` . `users` ";
 $result = mysqli_query($con, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($con), E_USER_ERROR); 
// Print the result

 if($result) {
while ($row = mysqli_fetch_assoc($result)) {
//	$query = "SELECT * FROM `bencobricks` . `users` WHERE `username` = username = $row[username]";
 printf ("%s\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n %s\n",
			"<label for='username'>Username: </label> <input type='text' name='username' value='$row[username]'>" . "</input><br/>",
			"<label for='email'>Email: </label> <input type='text' name='email' value='$row[email]'>" . "</input><br/>",
			"<label for='membership'>Membership: </label> <input type='text' name='membership' value='$row[membership]'>" . "</input><br/>",
			"<label for='firstName'>First name: </label> <input type='text' name='firstName' value='$row[firstName]'>" . "</input><br/>",
			"<label for='lastName'>Last name: </label> <input type='text' name='lastName' value='$row[lastName]'>" . "</input><br/>",
			"<label for='gender'>Gender: </label> <input type='text' name='gender' value='$row[gender]'>" . "</input><br/>",
			"<label for='dateOfBirth'>Birthdate: </label> <input type='text' name='dateOfBirth' value='$row[dateOfBirth]'>" . "</input><br/>",
			"<label for='date'>Date: </label> <input type='text' name='date' value='$row[date]'>" . "</input><br/>",
			"<label for='sets'>Sets: </label> <input type='text' name='sets' value='$row[sets]'>" . "</input><br/>",
			"<label for='checkbox'>Checkbox: </label> <input type='text' name='checkbox' value='$row[checkbox]'>" . "</input><br/>",
			"<label for='admin'>Admin? </label> <input type='text' name='admin' value='$row[adminFlag]'>" . "</input><BR>",
			
		"<br/><br/> ");
}
}
} 
mysqli_close($con);
?>

Any help is greatly appreciated. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.