Gayner Posted November 14, 2009 Share Posted November 14, 2009 Private?: <input type="checkbox" name="private" /> now my php for update is $private = $_POST['private']; mysql_query("INSERT INTO `prays` (`title` ,`text` ,`private` ,`time`) VALUES ( '". mysql_real_escape_string($_POST['title']) ."', '". mysql_real_escape_string($_POST['text']) ."', '". mysql_real_escape_string($_POST['private']) ."', '$time');"); and im getting: when it insert to database if somone clicks on the checkbox it still 0 i need it to be value =1 if somone clicks Link to comment https://forums.phpfreaks.com/topic/181556-checkbox-value-1-if-checked/ Share on other sites More sharing options...
Gayner Posted November 14, 2009 Author Share Posted November 14, 2009 ROFL ALL I HAD TO DO WAS ADD VALUE="1" LOL But what if, they dont check it? how can i add it so it changes the value to whatever i want? Link to comment https://forums.phpfreaks.com/topic/181556-checkbox-value-1-if-checked/#findComment-957660 Share on other sites More sharing options...
mrMarcus Posted November 14, 2009 Share Posted November 14, 2009 what do you want the value to be if they don't check it? Link to comment https://forums.phpfreaks.com/topic/181556-checkbox-value-1-if-checked/#findComment-957662 Share on other sites More sharing options...
FaT3oYCG Posted November 14, 2009 Share Posted November 14, 2009 That isn't how checkbox's work. Search into the isset(); function. A simple google search returns this: http://www.homeandlearn.co.uk/php/php4p11.html Link to comment https://forums.phpfreaks.com/topic/181556-checkbox-value-1-if-checked/#findComment-957663 Share on other sites More sharing options...
Gayner Posted November 14, 2009 Author Share Posted November 14, 2009 what do you want the value to be if they don't check it? 4 Link to comment https://forums.phpfreaks.com/topic/181556-checkbox-value-1-if-checked/#findComment-957666 Share on other sites More sharing options...
mrMarcus Posted November 14, 2009 Share Posted November 14, 2009 <?php if (isset ($_POST['private']) || (!empty ($_POST['private']))) { $private = 1; } else { $private = 4; } ?> Link to comment https://forums.phpfreaks.com/topic/181556-checkbox-value-1-if-checked/#findComment-957667 Share on other sites More sharing options...
Gayner Posted November 14, 2009 Author Share Posted November 14, 2009 <?php if (isset ($_POST['private']) || (!empty ($_POST['private']))) { $private = 1; } else { $private = 4; } ?> ty sir Link to comment https://forums.phpfreaks.com/topic/181556-checkbox-value-1-if-checked/#findComment-957668 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.