|
|
|
|
![]() ![]() |
Nov 20 2006, 12:16 AM
Post
#1
|
|
|
Premium Member Group: Members Posts: 250 Joined: 6-July 06 From: The net (or at least that's what my family says) Member No.: 14,330 |
I put together this:
CODE //Make Sure $qty is NOT blank before checking if it is a number if (!empty($item_1_qty)) { //not empty } if (intval($item_1_qty) !== $item_1_qty){ //item 1 qty is not a whole number $redirect_to = 'order_form.php?error=6'; header("Location: $redirect_to"); exit(); } But I get my error message coming no matter whether it is an integer or not. This post has been edited by ginginca: Nov 20 2006, 12:16 AM |
|
|
|
Nov 20 2006, 02:55 AM
Post
#2
|
|
|
Advanced Member Group: Members Posts: 187 Joined: 15-November 05 From: Inland from the Left Coast of Canada Member No.: 9,627 |
QUOTE if (intval($item_1_qty) !== $item_1_qty){ Where is the value for the $item_1_qty coming from? if it is coming from a form, it may be cast as a string and the php.net site lists a series of examples which you might be interested in reviewing. http://us3.php.net/manual/en/function.intval.php |
|
|
|
Nov 20 2006, 10:08 AM
Post
#3
|
|
|
Super Member Group: [HOSTED] Posts: 763 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 |
I put together this: CODE //Make Sure $qty is NOT blank before checking if it is a number if (!empty($item_1_qty)) { //not empty } if (intval($item_1_qty) !== $item_1_qty){ //item 1 qty is not a whole number $redirect_to = 'order_form.php?error=6'; header("Location: $redirect_to"); exit(); } But I get my error message coming no matter whether it is an integer or not. If your variable is coming from a form i reccomend you to cast it before you use it, its simple: CODE $item_1_qty = (int) $_POST['item_1_qty']; Also take a look to the is_numeric() php function, because it is recommended to use it with variables that are submited by a form. Best regards, |
|
|
|
Nov 23 2006, 05:52 PM
Post
#4
|
|
|
Super Member Group: Members Posts: 595 Joined: 4-September 04 Member No.: 228 |
PHP has a function called is_int() to test if parameter is integer. Why not just use that?
|
|
|
|
Nov 23 2006, 06:54 PM
Post
#5
|
|
|
the Q Group: [HOSTED] Posts: 1,054 Joined: 13-July 05 From: Lithuania, Vilnius Member No.: 7,059 |
..and why not better to use a function is_numeric() to see if the variable is a number or a numeric string, or you really need it to be integer.. But if so, the above replies have said enough.
|
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 13th October 2008 - 09:23 PM |