Jump to content

[SOLVED] check box, only check if user checked


DeanWhitehouse

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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