DeanWhitehouse Posted April 23, 2008 Share Posted April 23, 2008 in case the title didn't make sense , i will explain. how can i have it so if a user checks a box it stays checked and if they don't check it , it isn't checked?? also is there a way to have multiple check boxes with the same, but then how can i differ them when using an if(isset($_POST[''])) function as they have the same name(how else can they be intetifed) Link to comment https://forums.phpfreaks.com/topic/102442-solved-check-box-only-check-if-user-checked/ Share on other sites More sharing options...
teng84 Posted April 23, 2008 Share Posted April 23, 2008 this is not php this is javascript and on your second question show us how you code your check boxes Link to comment https://forums.phpfreaks.com/topic/102442-solved-check-box-only-check-if-user-checked/#findComment-524587 Share on other sites More sharing options...
skope Posted April 23, 2008 Share Posted April 23, 2008 check if the value has been submitted $callAttempt1 = $_REQUEST['callAttempt1']; write conditional echo into input tag <input name="callAttempt1" type="checkbox" id="callAttempt1" value="1" <?php if($checkbox] == 1) { echo("disabled checked=\"checked\""); };?> /> Link to comment https://forums.phpfreaks.com/topic/102442-solved-check-box-only-check-if-user-checked/#findComment-524589 Share on other sites More sharing options...
DeanWhitehouse Posted April 23, 2008 Author Share Posted April 23, 2008 if(isset($_POST['update'])) { if($user_email) { if($user_email == $user_email2) { mysql_query("UPDATE $user SET user_email = '$user_email' WHERE user_id = '$user_id'")or die('Could not update email: ' . mysql_error()); } else { echo "Email Addresses do not match"; } } if($user_password) { if($user_password == $user_password2) { mysql_query("UPDATE $user SET user_password = '$user_password' WHERE user_id = '$user_id'")or die('Could not change password: ' . mysql_error()); } else { echo "Passwords do not match"; } } if(isset($_POST['hideemail'])) { mysql_query("UPDATE $user SET show_email = '0' WHERE user_id = '$user_id'")or die('Could not change settings: ' . mysql_error()); } elseif(isset($_POST['hideemail'])) { mysql_query("UPDATE $user SET show_email = '1' WHERE user_id = '$user_id'")or die('Could not change settings: ' . mysql_error()); } } ?> <html> <table bgcolor='#999999' align='center' width="400px"> <form action='<?php $_SERVER['PHP_SELF']; ?>' method='POST'> <tr><td width="10px">Maximum Length<br /> 20 characters.</td></tr> <tr><td width="10px">E-mail Address:</td> <td><input type='text' name='user_email' value="<?php echo "$email"; ?>" /><br /></td></tr> <tr><td width="10px">Confirm E-mail Address: </td><td><input type='text' name='user_email2' value="<?php echo "$email"; ?>" /><br /></td></tr> <tr><td width="10px">Maximum Length<br /> 30 characters.</td></tr> <tr><td width="10px">New Password:</td><td> <input type='password' name='user_password' maxlength="30" /><br /></td></tr> <tr><td width="10px">Confirm Password:</td><td> <input type='password' name='user_password2' maxlength="30" /><br /></td></tr> <tr><td width="10px">Hide Email</td><td width="10px">Yes<input type="radio" value="0" name="hideemail"/> No<input type="radio" value="1" name="hideemail"/> </td></tr> <tr><td><input type='submit' value='Save Changes' name='update' /></td> </form> </table> </html> this is my code for the page where they can check the box, i want it so that if they check one it updates the database and if another updates it differently Link to comment https://forums.phpfreaks.com/topic/102442-solved-check-box-only-check-if-user-checked/#findComment-524590 Share on other sites More sharing options...
skope Posted April 23, 2008 Share Posted April 23, 2008 Both instances you're just checking if it's set... not the value. Test the submitted value... if($_POST['hideemail'] == 0 { mysql_query("UPDATE $user SET show_email = '0' WHERE user_id = '$user_id'")or die('Could not change settings: ' . mysql_error()); } else { mysql_query("UPDATE $user SET show_email = '1' WHERE user_id = '$user_id'")or die('Could not change settings: ' . mysql_error()); } Link to comment https://forums.phpfreaks.com/topic/102442-solved-check-box-only-check-if-user-checked/#findComment-524594 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.