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

Querying info from one table based on info in another
Hi, I am currently trying to make a part for my user driven website where one user can subscribe to

phpMailer will not connect using SMTP
I am trying to use phpMailer with smtp:

Code: [Select]$mailer = new PHPMailer();
$mailer-&

MySQL Primary key gap
Alright, so I have a table with 26 entries in it (id, filename, caption) for my image randomiser (ht

some questions
Hello,

I am looking for the answers for following questions:

1) Does PHP support overl

Need help to modify php ELSE code
I'm trying to find a way to have the php code display a message if there is no inventory listed in t

Placing and array within an array then sorting it!
I have a page that runs two large mysql queries and saves the results into arrays, in php I then per

Bluetooth RSSI & VIsta
Okie I got 4 Bluetooth adapters, a DBT-120 by Dlink, A Zonet Microsoft Bluetooth which is what I use

Batch update record with Pagination
Hoping someone can help me with this issue I'm having, im trying to batch update records from a resu

script and html conflict in trying to create a header.
I have an error is occurring because of an html webpage with a "php require" at the top of

How to display value in drop down list after form has been reloaded
Please bear with me as I am very new to php and html.

I have a form with several drop down me

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