More questions about PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
rax369
Forum Commoner
Posts: 56
Joined: Sun Oct 06, 2002 8:50 pm

More questions about PHP

Post 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:
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

answers

Post 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
User avatar
rax369
Forum Commoner
Posts: 56
Joined: Sun Oct 06, 2002 8:50 pm

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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';
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Use this code:-

Code: Select all

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