p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: missing variable text in browser


Message #1 by "Dai" <Dai1961@l...> on Mon, 4 Feb 2002 17:13:42
In the wrox book beginning php4 on page 101 the two variables  below that 

print out the person's first and lastnames doesn't show in the browser 

I've included the two lines of code from loan.html  and as you can see 

they are the same. 

if you can spot my mistake then I would be greatful if you point it out to 

me.



<INPUT TYPE="text" NAME="first_name">

<INPUT TYPE="text" NAME="last_name">





if ($loan <= $loan_allowance) echo "Yes, $first_name $last_name, we are 

delighted to accept your application";

if ($loan > $loan_allowance) echo "Sorry, $first_name $last_name, we 

cannot accept your loan application at this time";



Message #2 by "Nikolai Devereaux" <yomama@u...> on Mon, 4 Feb 2002 09:19:59 -0800

If your php.ini file doesn't have the line "register_globals = on", then

you'll have to access your form input variables via the $HTTP_GET_VARS and

$HTTP_POST_VARS arrays.



If your form method was GET, then you'd use $HTTP_GET_VARS['first_name'].



nik



> -----Original Message-----

> From: Dai [mailto:Dai1961@l...]

> Sent: Monday, February 04, 2002 5:14 PM

> To: beginning php

> Subject: [beginning_php] missing variable text in browser

>

>

> In the wrox book beginning php4 on page 101 the two variables  below that

> print out the person's first and lastnames doesn't show in the browser

> I've included the two lines of code from loan.html  and as you can see

> they are the same.

> if you can spot my mistake then I would be greatful if you point

> it out to

> me.

>

> <INPUT TYPE="text" NAME="first_name">

> <INPUT TYPE="text" NAME="last_name">

>

>

> if ($loan <= $loan_allowance) echo "Yes, $first_name $last_name, we are

> delighted to accept your application";

> if ($loan > $loan_allowance) echo "Sorry, $first_name $last_name, we

> cannot accept your loan application at this time";

>

>




> $subst('Email.Unsub').



Message #3 by "Dai" <Dai1961@l...> on Mon, 4 Feb 2002 20:14:12
This is the only reference to glabals I can find in php ini file and it 

looks like globals are already switched on?



; You should do your best to write your scripts so that they do not require

; register_globals to be on;  Using form variables as globals can easily 

lead

; to possible security problems, if the code is not very well thought of.

register_globals = On









Message #4 by "Nikolai Devereaux" <yomama@u...> on Mon, 4 Feb 2002 12:13:33 -0800

Show me the rest of your code then -- if you have register_globals = on in

php.ini then it should work.



I only have one other guess -- If your echo statements are in a function,

you'll have to declare those variables as globals, otherwise PHP will think

they are new local variables within the function scope and initialize them

to null since it's their "first use".



function whatever()

{

    global $first_name, $last_name;



    ...

}





nik



> -----Original Message-----

> From: Dai [mailto:Dai1961@l...]

> Sent: Monday, February 04, 2002 8:14 PM

> To: beginning php

> Subject: [beginning_php] RE: missing variable text in browser

>

>

> This is the only reference to glabals I can find in php ini file and it

> looks like globals are already switched on?

>

> ; You should do your best to write your scripts so that they do

> not require

> ; register_globals to be on;  Using form variables as globals can easily

> lead

> ; to possible security problems, if the code is not very well thought of.

> register_globals = On

>

>

>

>

>




> $subst('Email.Unsub').



Message #5 by "Dai" <Dai1961@l...> on Mon, 4 Feb 2002 21:36:19
> 

> Show me the rest of your code then -- if you have register_globals = on 

in

> php.ini then it should work.

This is the loan.html   file





<HTML>

<HEAD>

<!-- Minus AutoDato -->

	<TITLE>[No title]</TITLE>

<META NAME="Generator" CONTENT="Stone's WebWriter 3.5">

</HEAD>

<BODY>

<B>Namllu Credit Bank Loan Credit Loan Application Form</B>



<FORM ACTION="loan.php" METHOD="POST">

First name:

<INPUT TYPE="text" NAME="first_name">

Last Name:

<INPUT TYPE="text" NAME="last_name">

Age:

<INPUT TYPE="text" SIZE="3" NAME="age">

<BR><BR>

Address:

<TEXTAREA ROWS="4" COLS="40" NAME="address"></TEXTAREA>

<BR><BR>

What is your current salary?

<SELECT NAME="salary">

	<OPTION VALUE="0">Under 10,000

	<OPTION VALUE="10000">$10,000 to $25,000

	<OPTION VALUE="25000">$25,000 to $50,000

	<OPTION VALUE="50000">$50,000

</SELECT>

<BR><BR>

How much do you want to borrow?

<BR><BR>

<INPUT TYPE="radio" VALUE="1000" NAME="loan" CHECKED>Our 1,000 package at 

8.5%<BR>

<INPUT TYPE="radio" VALUE="5000" NAME="loan" CHECKED>Our 5,000 package at 

11.5%<BR>

<INPUT TYPE="radio" VALUE="10000" NAME="loan" CHECKED>Our 10,000 package 

at 15.%<BR>

<BR><INPUT TYPE="submit" VALUE="Click here to Submit application">

<INPUT TYPE="reset" VALUE="Reset application form">

</FORM>





</BODY>

</HTML>



and this is the loan.php   file



<HTML>

<HEAD>

<!-- Minus AutoDato -->

	<TITLE>loan</TITLE>

<META NAME="Generator" CONTENT="Stone's WebWriter 3.5">

</HEAD>

<BODY>



<B>Namllu Credit Bank Loan Credit Loan Application Form</B>

<BR><BR>

<?php

if ($age <10 OR $age >40)

{

	echo "Incorrect age entered - Press the back button to try again";

	exit;

}

if ($first_name ="" OR  $last_name = "")

{

	echo "You must enter your name - Press the back button to try 

again";

	exit;

}

if ($address =="")

{

	echo " You must enter your address - Press the back button to try 

again";

	exit;

}

if ($loan !=1000 and $loan != 5000 and $loan !=10000)

{

	echo " You must enter a loan value - Press the back button to try 

again";

	exit;

}

$salary_allowance = $salary/5;

$age_allowance = ($age/10 - ($age%10) /10) -1;

$loan_allowance = $salary_allowance * $age_allowance;

echo "Loan wanted:$loan<BR>";

echo "Loan amount we will allow:$loan_allowance<BR><BR>";

if ($loan <= $loan_allowance) echo "Yes, $first_name $last_name, we are 

delighted to accept your application";

if ($loan > $loan_allowance) echo "Sorry, $first_name $last_name, we 

cannot accept your loan application at this time";



?>





</BODY>

</HTML>

Message #6 by "Nikolai Devereaux" <yomama@u...> on Mon, 4 Feb 2002 17:51:24 -0800

Why do you have each of your radio buttons marked as "checked"?  A series of

radio inputs with the same name can only have one checked value.



and here's your problem:



> if ($first_name ="" OR  $last_name = "")

> {

> 	echo "You must enter your name - Press the back button to try

> again";

> 	exit;

> }





You're SETTING $first_name and $last_name to "".  You need a double-equals

here ('==').



take care,



nik



Message #7 by "Dai" <Dai1961@l...> on Tue, 5 Feb 2002 17:43:09
Cheers Nik I couldn't see the wood for the trees there. Simple mistake I 

should of picked that one up.



thanks 



Dai







> Why do you have each of your radio buttons marked as "checked"?  A 

series of

> radio inputs with the same name can only have one checked value.

> 

> and here's your problem:

> 

> > if ($first_name ="" OR  $last_name = "")

> > {

> > 	echo "You must enter your name - Press the back button to try

> > again";

> > 	exit;

> > }

> 

> 

> You're SETTING $first_name and $last_name to "".  You need a double-

equals

> here ('==').

> 

> take care,

> 

> nik

> 

Message #8 by "Nikolai Devereaux" <yomama@u...> on Tue, 5 Feb 2002 09:40:06 -0800

No worries, i'm glad to have helped!



Nik



> -----Original Message-----

> From: Dai [mailto:Dai1961@l...]

> Sent: Tuesday, February 05, 2002 5:43 PM

> To: beginning php

> Subject: [beginning_php] RE: missing variable text in browser

> 

> 

> Cheers Nik I couldn't see the wood for the trees there. Simple mistake I 

> should of picked that one up.

> 

> thanks 

> 

> Dai

> 

> 

> 

> > Why do you have each of your radio buttons marked as "checked"?  A 

> series of

> > radio inputs with the same name can only have one checked value.

> > 

> > and here's your problem:

> > 

> > > if ($first_name ="" OR  $last_name = "")

> > > {

> > > 	echo "You must enter your name - Press the back button to try

> > > again";

> > > 	exit;

> > > }

> > 

> > 

> > You're SETTING $first_name and $last_name to "".  You need a double-

> equals

> > here ('==').

> > 

> > take care,

> > 

> > nik

> > 

> 




> $subst('Email.Unsub').


  Return to Index