penguin0 Posted May 22, 2007 Share Posted May 22, 2007 I am currently making an edit user page, and it all works so far. One problem is I have it echo a user's permissions in radio buttons, with an if statement. uusers is a variable printing if the user being edited has the perm "users" and so on. Look for this part of the code: <tr><td>Regular User?</td><td><input type="radio" name="users" value="1"<? if ($uusers == "1") { echo " checked=\"1\""; } ?>> Yes <input type="radio" name="users" value="0" <? if ($uusers == "0") { echo " checked=\"1\""; } ?>> No</td></tr> The problem is if the user manager clicks the perm something other than the one that is selected it will not save, because I have it echoing checked=1 so it will show the users perms. Anyone know another if statement I can put in for if a perm is changed, so it will update? All the code: <? include("header2.php"); ?> <? $result = mysql_query( "SELECT content FROM pages WHERE number = 4" ); $num_rows = mysql_num_rows( $result ); while ( $a_row = mysql_fetch_row( $result ) ) { foreach ( $a_row as $field ) print "$field"; } ?> <? $userid = intval($_REQUEST['id']); $sql = "SELECT id, name, position, username, email, admin, pageman, userman, rateman, menuman, users, created FROM users WHERE id = $userid"; $result = mysql_query($sql, $link) or die(mysql_error()); while ( $a_row = mysql_fetch_array( $result ) ) { $id = $a_row['id']; $name = $a_row['name']; $username = $a_row['username']; $position = $a_row['position']; $uadmin = $a_row['admin']; $upageman = $a_row['pageman']; $uuserman = $a_row['userman']; $urateman = $a_row['rateman']; $umenuman = $a_row['menuman']; $uusers = $a_row['users']; $email = $a_row['email']; $created = $a_row['created']; } ?> <form action="do_edituser.php" method="POST"> <table cellpadding=2 cellspacing=1 class=ptable><tr><th colspan=2>Edit User: <? echo "$name"; ?></th></tr> <tr><td>Name:</td><td><input type="text" name="name" size="25" maxlength="25" value="<? echo "$name"; ?>"></td></tr> <tr><td>Position:</td><td><input type="text" name="position" size="25" maxlength="35" value="<? echo "$position"; ?>"></td></tr> <tr><td>Username:</td><td><input type="text" name="username" size="25" maxlength="25" value="<? echo "$username"; ?>"></td></tr> <tr><td>Email:</td><td><input type="text" name="email" size="35" maxlength="50" value="<? echo "$email"; ?>"></td></tr> <tr><td>Created:</td><td><? echo "$created"; ?></td></tr> <tr><th colspan=2>Edit Permissions</th></tr> <input type="hidden" name="id" value="<? echo "$_POST[id]"; ?>"> <tr><td>Is Admin?</td><td><input type="radio" name="admin" value="1" <? if ($uadmin == "1") { echo "checked=\"1\""; } ?>> Yes <input type="radio" name="admin" value="0"<? if ($uadmin == "0") { echo " checked=\"1\""; } ?>> No</td></tr> <tr><td>Edit Pages?</td><td><input type="radio" name="pageman" value="1"<? if ($upageman == "1") { echo " checked=\"1\""; } ?>> Yes <input type="radio" name="pageman" value="0"<? if ($upageman == "0") { echo " checked=\"1\""; } ?>"> No</td></tr> <tr><td>Edit Menus?</td><td><input type="radio" name="menuman" value="1"<? if ($umenuman == "1") { echo " checked=\"1\""; } ?>> Yes <input type="radio" name="menuman" value="0"<? if ($umenuman == "0") { echo " checked=\"1\""; } ?>> No</td></tr> <tr><td>Approve Rates?</td><td><input type="radio" name="rateman" value="1"<? if ($urateman == "1") { echo " checked=\"1\""; } ?>> Yes <input type="radio" name="rateman" value="0"<? if ($urateman == "0") { echo " checked=\"1\""; } ?>> No</td></tr> <tr><td>Edit Users?</td><td><input type="radio" name="userman" value="1"<? if ($uuserman == "1") { echo " checked=\"1\""; } ?>> Yes <input type="radio" name="userman" value="0"<? if ($uuserman == "0") { echo " checked=\"1\""; } ?>> No</td></tr> <tr><td>Regular User?</td><td><input type="radio" name="users" value="1"<? if ($uusers == "1") { echo " checked=\"1\""; } ?>> Yes <input type="radio" name="users" value="0" <? if ($uusers == "0") { echo " checked=\"1\""; } ?>> No</td></tr> <tr><td align=center colspan=2><input type="submit" name="submit" value="Update User"></td></tr></table> </form> </td></tr> <? include("footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52521-solved-if-statement-help/ Share on other sites More sharing options...
valtido Posted May 22, 2007 Share Posted May 22, 2007 hey sorry but u got some html elementry errors 1 i dont think u can use checked="1" instead use checked="checked" 2 i dont really see you grouping any of the radio buttons. try an group them by label tags like so <label><input type=radio />yes <input type=radio checked=checked /> No</label> 3 you got a php problem... on the line that says ...checked=1 <? if .... its a bit wrong because you have already told it that it should be checked and you can't remove it 4 i just think your missing out on the label tags which you dont really need to use php to check and uncheck them. 5 hope it helped somehow Quote Link to comment https://forums.phpfreaks.com/topic/52521-solved-if-statement-help/#findComment-259238 Share on other sites More sharing options...
penguin0 Posted May 22, 2007 Author Share Posted May 22, 2007 The way it was before was correct html, except for the checked = 1, but It showed correctly. That was not my issue. My issue is when I change the value from yes to no or from no to yes, it wont update. I used the if statement to find in the db if the user has the perm or not, and show it when you go to edit them. Anyone know how I can change my if statement to reflect the change before it saves? updated code: <tr><td>Is Admin?</td><td><label><input type="radio" name="admin" value="1" <? if ($uadmin == "1") { echo "checked=\"checked\""; } ?>/> Yes <input type="radio" name="admin" value="0"<? if ($uadmin == "0") { echo " checked=\"checked\""; } ?>/> No</label></td></tr> <tr><td>Edit Pages?</td><td><label><input type="radio" name="pageman" value="1"<? if ($upageman == "1") { echo " checked=\"checked\""; } ?>/> Yes <input type="radio" name="pageman" value="0"<? if ($upageman == "0") { echo " checked=\"checked\""; } ?>/> No</label></td></tr> <tr><td>Edit Menus?</td><td><label><input type="radio" name="menuman" value="1"<? if ($umenuman == "1") { echo " checked=\"checked\""; } ?>/> Yes <input type="radio" name="menuman" value="0"<? if ($umenuman == "0") { echo " checked=\"checked\""; } ?>/> No</label></td></tr> <tr><td>Approve Rates?</td><td><label><input type="radio" name="rateman" value="1"<? if ($urateman == "1") { echo " checked=\"checked\""; } ?>/> Yes <input type="radio" name="rateman" value="0"<? if ($urateman == "0") { echo " checked=\"checked\""; } ?>/> No</label></td></tr> <tr><td>Edit Users?</td><td><label><input type="radio" name="userman" value="1"<? if ($uuserman == "1") { echo " checked=\"checked\""; } ?>/> Yes <input type="radio" name="userman" value="0"<? if ($uuserman == "0") { echo " checked=\"checked\""; } ?>/> No</label></td></tr> <tr><td>Regular User?</td><td><label><input type="radio" name="users" value="1"<? if ($uusers == "1") { echo " checked=\"checked\""; } ?>/> Yes <input type="radio" name="users" value="0" <? if ($uusers == "0") { echo " checked=\"checked\""; } ?>/> No</label></td></tr> Quote Link to comment https://forums.phpfreaks.com/topic/52521-solved-if-statement-help/#findComment-259336 Share on other sites More sharing options...
penguin0 Posted May 24, 2007 Author Share Posted May 24, 2007 Does anyone have an idea on this? Quote Link to comment https://forums.phpfreaks.com/topic/52521-solved-if-statement-help/#findComment-260420 Share on other sites More sharing options...
hitman6003 Posted May 24, 2007 Share Posted May 24, 2007 Not sure what you mean by "before it saves". If you change the value, then click update, and it doesn't update, that generally means that there is a problem with the update script, not the display script. On a different note, you can also use the ternary operator to do the "checking" of radio buttons... <tr> <td>Is Admin?</td> <td> <label> <input type="radio" name="admin" value="1" <? echo ($uadmin == 1) ? 'checked="checked"' : ''; ?> /> Yes <input type="radio" name="admin" value="0" <? echo ($uadmin == 0) ? 'checked="checked"' : ''; ?> /> No </label> </td> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/52521-solved-if-statement-help/#findComment-260423 Share on other sites More sharing options...
penguin0 Posted May 24, 2007 Author Share Posted May 24, 2007 well if that does work, i still have a problem, I am using an if statement to test for a perm, and if its true, it will echo all the html now, so how do I use the if statements now? You cannot use it inside the echo right? Quote Link to comment https://forums.phpfreaks.com/topic/52521-solved-if-statement-help/#findComment-260432 Share on other sites More sharing options...
hitman6003 Posted May 24, 2007 Share Posted May 24, 2007 The ternary operator replaces an if...else statement... <? echo ($uadmin == 1) ? 'checked="checked"' : ''; ?> replaces <? if ($upageman == "1") { echo " checked=\"checked\""; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52521-solved-if-statement-help/#findComment-260435 Share on other sites More sharing options...
penguin0 Posted May 24, 2007 Author Share Posted May 24, 2007 I know that but all the html on the page gets echo if the user has the perm to edit users (if not the user gets an acces denied). So all this needs to be echoed: <tr><td>Is Admin?</td><td><label><input type="radio" name="admin" value="1" <? if ($uadmin == "1") { echo "checked=\"checked\""; } ?>/> Yes <input type="radio" name="admin" value="0"<? if ($uadmin == "0") { echo " checked=\"checked\""; } ?>/> No</label></td></tr> <tr><td>Edit Pages?</td><td><label><input type="radio" name="pageman" value="1"<? if ($upageman == "1") { echo " checked=\"checked\""; } ?>/> Yes <input type="radio" name="pageman" value="0"<? if ($upageman == "0") { echo " checked=\"checked\""; } ?>/> No</label></td></tr> <tr><td>Edit Menus?</td><td><label><input type="radio" name="menuman" value="1"<? if ($umenuman == "1") { echo " checked=\"checked\""; } ?>/> Yes <input type="radio" name="menuman" value="0"<? if ($umenuman == "0") { echo " checked=\"checked\""; } ?>/> No</label></td></tr> <tr><td>Approve Rates?</td><td><label><input type="radio" name="rateman" value="1"<? if ($urateman == "1") { echo " checked=\"checked\""; } ?>/> Yes <input type="radio" name="rateman" value="0"<? if ($urateman == "0") { echo " checked=\"checked\""; } ?>/> No</label></td></tr> <tr><td>Edit Users?</td><td><label><input type="radio" name="userman" value="1"<? if ($uuserman == "1") { echo " checked=\"checked\""; } ?>/> Yes <input type="radio" name="userman" value="0"<? if ($uuserman == "0") { echo " checked=\"checked\""; } ?>/> No</label></td></tr> <tr><td>Regular User?</td><td><label><input type="radio" name="users" value="1"<? if ($uusers == "1") { echo " checked=\"checked\""; } ?>/> Yes <input type="radio" name="users" value="0" <? if ($uusers == "0") { echo " checked=\"checked\""; } ?>/> No</label></td></tr> Quote Link to comment https://forums.phpfreaks.com/topic/52521-solved-if-statement-help/#findComment-260439 Share on other sites More sharing options...
hitman6003 Posted May 24, 2007 Share Posted May 24, 2007 echo ' <tr> <td>Is Admin?</td> <td> <label> <input type="radio" name="admin" value="1" ' . ($uadmin == 1 ? 'checked="checked"' : '') . ' /> Yes <input type="radio" name="admin" value="0" ' . ($uadmin == 0 ? 'checked="checked"' : '') . ' /> No </label> </td> </tr> ....and so on for the others....'; Quote Link to comment https://forums.phpfreaks.com/topic/52521-solved-if-statement-help/#findComment-260443 Share on other sites More sharing options...
penguin0 Posted May 24, 2007 Author Share Posted May 24, 2007 well it echoed everything correctly, even the perms the user already has, but when I click submit it wont update the perm. I have the second page that it shows what was updated and (i changed userman from 0 to 1: Admin perm? 0 Page perm? 0 User perm? 1 Rate perm? 0 Menu perm? 0 Reg perm? 1 it posted like it updated, but didn't. Quote Link to comment https://forums.phpfreaks.com/topic/52521-solved-if-statement-help/#findComment-260448 Share on other sites More sharing options...
hitman6003 Posted May 24, 2007 Share Posted May 24, 2007 but when I click submit it wont update the perm. So it's an issue with the update script...not the html display Quote Link to comment https://forums.phpfreaks.com/topic/52521-solved-if-statement-help/#findComment-260451 Share on other sites More sharing options...
penguin0 Posted May 24, 2007 Author Share Posted May 24, 2007 bah, someone hit me, ID was not posting, GAWSH! Quote Link to comment https://forums.phpfreaks.com/topic/52521-solved-if-statement-help/#findComment-260454 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.