Perad Posted October 16, 2006 Share Posted October 16, 2006 I have this code to check to see if information is entered into the form...[code]if (empty($_POST['oppscore1'])) { $os1 = FALSE; $message .= '<p>You forgot to enter the Opponents Score ht!</p>';} else { $os1 = $_POST['oppscore1'];}[/code]Unfortunately when i enter "0" into the form field for Score, it gets rejected because it thinks 0(Zero) isn't a number/value.Could someone help me correct this please. Perad Link to comment https://forums.phpfreaks.com/topic/24094-making-0-a-value/ Share on other sites More sharing options...
Daniel0 Posted October 16, 2006 Share Posted October 16, 2006 [code]$num = intval(0);[/code]or[code]$num = (int) 0;[/code] Link to comment https://forums.phpfreaks.com/topic/24094-making-0-a-value/#findComment-109511 Share on other sites More sharing options...
xsist10 Posted October 16, 2006 Share Posted October 16, 2006 [quote author=Perad link=topic=111650.msg452590#msg452590 date=1161005954][code]if (empty($_POST['oppscore1'])) { $os1 = FALSE; $message .= '<p>You forgot to enter the Opponents Score ht!</p>';} else { $os1 = $_POST['oppscore1'];}[/code][/quote]Much better to use:[code]<?phpif (isset($_POST['oppscore1'])) { $os1 = FALSE; $message .= '<p>You forgot to enter the Opponents Score ht!</p>';} else { $os1 = $_POST['oppscore1'];}?>[/code] Link to comment https://forums.phpfreaks.com/topic/24094-making-0-a-value/#findComment-109524 Share on other sites More sharing options...
neoform Posted October 16, 2006 Share Posted October 16, 2006 um, isset($_POST['field_name']) will return true if that form item exists.. not if it's been filled out.You're better checking strlen(trim($_POST['field_name'])) to see how long the entered info is.. if someone types a 0 it'll be 1 char long. Link to comment https://forums.phpfreaks.com/topic/24094-making-0-a-value/#findComment-109525 Share on other sites More sharing options...
Daniel0 Posted October 16, 2006 Share Posted October 16, 2006 Just use is_numerical. Link to comment https://forums.phpfreaks.com/topic/24094-making-0-a-value/#findComment-109528 Share on other sites More sharing options...
alpine Posted October 16, 2006 Share Posted October 16, 2006 is_numeric() will work, also this is an approach to detect "real" empty[code]<?phpif(empty($_POST['oppscore1']) && !preg_match("/^[0]+$/", $_POST['oppscore1'])){ echo "is genuine empty and a 0 is not here";}else{ echo "is not empty and counting 0 as a value";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/24094-making-0-a-value/#findComment-109641 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.