Page 1 of 1

More questions about PHP

Posted: Sun Oct 27, 2002 7:15 pm
by rax369
1) I tried to use the function is_int() which u guys, suggested me to use, in order to validate the info coming from my form and use it later to make some calculations. But I dont know what I'm doing bad 'coz I dont get the wished result. All what I need is that the validation, test if the variable $_POST[processors_cant] is an integer or not. (or preferred if is >0 (only natural numbers... thx hob_goblin to remember me the math classes... jejeje :lol: )

Look at how I tried to use the function:
1st. one:

Code: Select all

if ( is_int( $_POSTїprocessors_cant] == "TRUE" )
{
   do something;
}
2nd. one:

Code: Select all

if( is_int( $_POSTїprocessors_cant] )
{
   do something;
}
2) Is there some function in PHP to show some message for x seconds on the screen and after that do another process ?

3) I would like to know what's the function in PHP to finish or exit the process or validation doing at that moment.

i.e

Code: Select all

if ($a == 1)
{
   do something;
}
else
{
  $a=2;
   exit( ); <-- abort or leave... I dont how is named this kind of functions
&#125;
I'm looking for the kind of function that leave or go out the loop or condition which is been performed at that moment, u understand me right ? :oops:

answers

Posted: Sun Oct 27, 2002 11:04 pm
by AVATAr
1) try:

Code: Select all

&lt;?php
if( is_int( $_POST&#1111;"processors_cant"] ) 
{ 
   do something; 
} 
?&gt;
2) php is only server side, so you cant do that, try javascipt

3)

Code: Select all

&lt;?php
die();
?&gt;
hope it helps

Posted: Sun Oct 27, 2002 11:34 pm
by rax369
thx for ur reply man, but that continues, not working at all... :x

I have tried (as u suggested):

Code: Select all

<?php 
if( !is_int( $_POST&#1111;"processors_cant"] )  
&#123;  
   echo "has not been set";
&#125;  
?>
also:

Code: Select all

<?php 
if( !is_int( $_POST&#1111;'processors_cant'] ) 
&#123;  
   echo "has not been set";
&#125;  
?>
and finally:

Code: Select all

<?php 
if( !is_int( $_POST&#1111;processors_cant] ) 
&#123;  
   echo "has not been set";
&#125;  
?>
but none works :!: ( the same happend with empty() )

my understanding is that the "if" conditions is TRUE, it should allow execute the code between "{ }" right... if the variable "processors_cant" has not been set is because the variable is empty (or am I wrong ?)

What I need to do is very simple, but none of the functions I have tried has worked the way it should works. I need to validate if the variable "processors_cant" which is coming from a form, has a value, I mean if the user in the form introduced some value, and if has not been introduced nothing inside it (using a text field in a form) then that should be empty or not set right ?

I have tried using the functions empty() and isset(), but nothing worked, and I have leaved the text field empy to test if the validation is taken effect but the message "has not been set" never shows up on the screen

Posted: Mon Oct 28, 2002 1:03 am
by volka
Always take a look at the server's errorlog (for apache: <apachedir>/logs/error.log). There's a closing bracket missing in your if-statements, maybe a typo here.

Since something's supposed to be either true or false and nothing inbetween, something MUST show up:

Code: Select all

echo '&lt;pre&gt;'; print_r($_POST); echo '&lt;/pre&gt;';
if ( !isset($_POST&#1111;'processors_cant']) )
	echo 'not set at all';
else
{
	echo 'set&lt;br/&gt;';
	if( !is_int($_POST&#1111;'processors_cant']) )
		echo 'is not an integer';
	else
	{
		echo 'is an integer&lt;br/&gt;';
		if ($_POST&#1111;'processors_cant']&gt;0)
			echo 'greater than 0';
		else
			echo 'not greater than 0';
	}
}
if you always have a confirmation page you may also use

Code: Select all

if ( (int)($_POST&#1111;"processors_cant"]) &gt; 0)
	echo 'somehow valid';
else
	echo 'not valid at all';

Posted: Mon Oct 28, 2002 1:31 am
by Takuma
Use this code:-

Code: Select all

&lt;?php
if(ereg("^&#1111;0-9]*$",$int)) {
settype($int,"integer");
}
?&gt;