Russia Posted March 25, 2011 Share Posted March 25, 2011 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 More sharing options...
btherl Posted March 25, 2011 Share Posted March 25, 2011 You are using mysql_num_rows() instead of mysql_fetch_array(). Also you have no error checking. Link to comment https://forums.phpfreaks.com/topic/231652-select-dropdown-based-on-row-value/#findComment-1192003 Share on other sites More sharing options...
Russia Posted March 25, 2011 Author Share Posted March 25, 2011 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. Link to comment https://forums.phpfreaks.com/topic/231652-select-dropdown-based-on-row-value/#findComment-1192008 Share on other sites More sharing options...
btherl Posted March 25, 2011 Share Posted March 25, 2011 Try checking empty($_GET['id']) only, and don't check isset(). Note that this will fail if id=0, but that doesn't matter if 0 is invalid anyway. Link to comment https://forums.phpfreaks.com/topic/231652-select-dropdown-based-on-row-value/#findComment-1192012 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.