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 Quote Link to comment 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] Quote Link to comment 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] Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted October 16, 2006 Share Posted October 16, 2006 Just use is_numerical. Quote Link to comment 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] Quote Link to comment 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.