Jump to content

Select dropdown based on row value


Russia

Recommended Posts

 

Hey guys, I am wanting to select a dropdown value based on the value of 'level' in the row of the user select by a $_GET.

 

 

It will house the ranks of the user.

 

 

Here is my script.

 

 

RANK
<?php
	mysql_connect("localhost","root","") or die(mysql_error());
	mysql_select_db("chat");


	$result = mysql_query("SELECT * FROM users WHERE user_id = '$_GET[id]'");
	$row = mysql_num_rows($result);
	?>




<form id="main_form" name="main_form" method="post" action="">
<select name="rank">
<option value="0" <?php if($row['level']=="0") { echo "selected"; }?>>Unactivated</option>
<option value="1" <?php if($row['level']=="1") { echo "selected"; }?>>Banned</option>
<option value="2" <?php if($row['level']=="2") { echo "selected"; }?>>Regular User</option>
<option value="3" <?php if($row['level']=="3") { echo "selected"; }?>>Donator</option>
<option value="4" <?php if($row['level']=="4") { echo "selected"; }?>>Moderator</option>
<option value="5" <?php if($row['level']=="5") { echo "selected"; }?>>Administrator</option>
<option value="6" <?php if($row['level']=="6") { echo "selected"; }?>>Owner</option>


</select>
<input type="submit" id="main_submit" name="main_submit" value="submit" />
</form>

 

 

It is not selecting for some reason at all.

 

 

 

 

Can someone tell me what I am doing wrong?

 

 

Link to comment
https://forums.phpfreaks.com/topic/231652-select-dropdown-based-on-row-value/
Share on other sites

Thanks, one more thing, How would I show a message if the  $_GET is  not set or if its empty.

 

I have tried

 

<?php
if(!isset($_GET['id']) && empty($_GET['id']) ) { 
echo 'Category not specified'; 
}
else
{
	mysql_connect("localhost","root","") or die(mysql_error());
	mysql_select_db("chat");
	//$strSQL = "SELECT * FROM users WHERE CharacterId = '$_GET['id']'"
	$result = mysql_query("SELECT level FROM users WHERE user_id = '$_GET[id]'");
	$query = mysql_fetch_array($result);
	?>
<form id="main_form" name="main_form" method="post" action="">
<select name="rank">
<option value="0" <?php if($query['level']=="0") { echo "selected"; }?>>Unactivated</option> 
<option value="1" <?php if($query['level']=="1") { echo "selected"; }?>>Banned</option> 
<option value="2" <?php if($query['level']=="2") { echo "selected"; }?>>Regular User</option> 
<option value="3" <?php if($query['level']=="3") { echo "selected"; }?>>Donator</option> 
<option value="4" <?php if($query['level']=="4") { echo "selected"; }?>>Moderator</option> 
<option value="5" <?php if($query['level']=="5") { echo "selected"; }?>>Administrator</option> 
<option value="6" <?php if($query['level']=="6") { echo "selected"; }?>>Owner</option> 

</select>
<input type="submit" id="main_submit" name="main_submit" value="submit" />
</form>
<?php } ?>

 

but it still shows the form if I have something like: http://localhost/yanille/edituser.php?id=

 

Basically without the actual number after the equals sign.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.