Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

Numeric text value

General discussions related to php

Moderators: macek, egami, gesf

Numeric text value

Postby Vannessa » Wed Sep 17, 2003 1:47 pm

Hi,Im new to Php and would like to know
how I can make sure a variable inputted is
an integer and not a cararacter.
On this form,the "score" textbox should
only have an integer typed in.

<form action="tally.php" method="post">
Score :
<input type="text" name="score">
<br/>
<input type="submit" name="Submit" value="Submit">
</p></form>
How would I verify this on the tally.php page,once
I have pressed submit?
Thank You.
Vannessa
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Sep 17, 2003 1:37 pm
Location: toronto

Postby Joel » Wed Sep 17, 2003 2:46 pm

On tally.php you would have some code like this.

Code: Select all
if (isset($_POST['Submit'])) {
      //Check for numericness
      if (!is_numeric($_POST['score'])) {
             //process form
      }  else {
            //echo error
      }

}

Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

Postby Vannessa » Thu Sep 18, 2003 2:36 pm

That's what I used,The is_numeric() function.Thanks.
Vannessa
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Sep 17, 2003 1:37 pm
Location: toronto


Return to PHP General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.