Checking if field is empty AND using !is_numeric


Posted on 16th Feb 2014 07:03 pm by admin

Hi lads,

Need to be able to display an error message (using isset?) that says "Cant leave field blank" when someone clicks on submit after leaving the field blank. The problem is that I'm also using the !is numeric function and that has an error message of "please enter numbers only" . Problem is that if someone leaves the field blank, the !is_numeric function picks up that there are no numbers before isset does and therefore outputs "please enter numbers" .

Anyone have any idea's how to fix this ?
My code is :

| <?phpfunction validate_form(){ $entered_grade = trim($_REQUEST['entergrade']); $error = ''; if (! isset($entered_grade)) { $error .= "<span class="error">You cannot leave the grade blank. Enter a mark between 0 and 100.</span>
"; }if (! is_numeric($entered_grade)) { $error .= "<span class="error">Invalid Input. You must enter a NUMBER between 0 and 100</span>
"; } if ($entered_grade >=101 ) { $error .= "<span class="error">Invalid Input. The marks must be between 0 and 100.</span>
"; } return $error;}

Thanks

No comments posted yet

Your Answer:

Login to answer
262 Like 9 Dislike
Previous forums Next forums
Other forums

Saving PHP output as a file
I wondered if anyone knows how to save the rendered output of a PHP script as a file?

I have

Parse error: parse error in C:wampwwwlogspagesmembers.php on line 16
I dont see the problem with this, I always get Parse error: parse error in C:wampwwwlogspagesme

Automatically Detect Phone Model for WAP Jar Deployment
Making a wap site is fairly simple, but I'd like to know if there's a way to make it so that the wap

How to get all server headers like Live http Headers does
Hey all, like many of you I use the Firefox addon "Live http Headers". I'm trying to write

HOW to get the bind variables list.
I've the following problem : I've some SQL queries stored in my DB as VARCHAR2 values.
I need t

PHP form authentication
Hi guys,

what am trying to achieve is this: Whenever a user tries to login to my website, an

Uploading Filetypes and placing them in seperate folders.
Hello,

first post , and asking for help im afraid. Very new to PHP, was making good progress

C problem struct and string
Hi guys,

This is my first post and I'm hoping the experts here can help me solve my problem.<

Easy administration on MySQL databases
My website is database driven and I am very tired of manually making queries to my tables in order t

MySQL query problem
When I try to run the following piece of code, I get this error:
QuoteWarning: mysql_query(): sup

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash