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

url- go to webpage
i have an input text field and submit button.

how do i make the url entered into the textfiel

Creating an invoice
Using fpdf I am trying to create an invoice to send to clients. The products are sold in pricing tie

help with php
It's not displaying or pulling anything out of the database.


Code: <html><

BackButton Behaviour in AJAX
I have an ASPX Page AJAX Enabled!The page has a gridView and a DDL for filtering on it. The Gridview

Strip Slashes Help
I've got a script that i've downloaded of the net to edit multiple fields from my sql database, and

bind error during socket programming
i am kinda new to socket programming. wrote the below code for a server. but getting the bind error

How to login with SAPCPIC userid
I have changed the Password for SAPCPIC in Development Server for 000,001 and 100 client.
But w

Putting double spaces instead of single spaces
Im looking at trying to replace all single spacing between fields with double spacing

At pres

Referential Integrity problem when inserting into 2 tables at same time
Hello Everyone,

Im relativity new to PHP and MySQL and i have come up against a problem. i h

Mastering Regular Expressions, Third Edition, is available.
The Third Edition of Mastering Regular Expressions is available.

QuoteThis third edition is 5

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