Page 1 of 1

NewBee Question

Posted: Sat Feb 21, 2004 7:28 pm
by ut1205
I have a defined variable lets call it:

Code: Select all

<?php
$LastName =  Smith;
?>
The value "Smith" was not user entered in a form. No "Post" or "Get" statement was used to arrive at the value but the value changes as a result of SQL Quries.

How can I pass the value of $LastName to the next page. Post and Get work fine if it is User Entered in a Form but this value is not.

I have tried to pass it in the URL with a statement such as this:

Code: Select all

<?php
<form action="deleteexe.php?Last=$LastName Method="post">;
?>
but all it passes along is the text "$LastName"

Help!!

Posted: Sat Feb 21, 2004 7:35 pm
by uberpolak
You need to touch up your quoting skills a tad.

Code: Select all

<?php
$lastname = 'Smith';
//now PHP knows you're giving it a string of text
?>
And your form tag was missing a quote after $lastname:

Code: Select all

<?php
<form action="deleteexe.php?last=$lastname" method="post">
?>
That should help you out a bit.

Thanks but still the same problem

Posted: Sat Feb 21, 2004 7:59 pm
by ut1205
When I put in:

<form action="deleteexe.php?last=$lastname" method="post">

and then on the next page put:

echo $last

all it will echo is "$lastname" not "Smith"

Am I still doing something wrong?

Posted: Sat Feb 21, 2004 8:16 pm
by uberpolak
Is the variable in a string which is singlequoted? For example:

Code: Select all

<?php
echo '$lastname';
?>
That will cause the problem you're having. If you need it to be in quotes (e.g. if there's more to the string) you could use double-quotes, or if not, drop the quotes altogether. That would solve your problem, if that's the problem.

Here's the test script

Posted: Sat Feb 21, 2004 8:32 pm
by ut1205
I guess I shouldn't use "" for emphasis. I created 2 new pages to be sure that other code wasn't getting in the way

Here's page one called passon.php

Code: Select all

<?php

<HTML>

<HEAD>

</HEAD>

<BODY>

<?php

$dummie = 'Stupid';
echo $dummie;

?>

<form action="passon2.php?crazy=$dummie" method="post">

<INPUT TYPE=SUBMIT NAME="Submit" VALUE="Submit!">

</BODY>

</HTML>
?>
The echo statement works fine on the first page
Here's the second page called passon2.php

Code: Select all

<?php
<HTML>

<HEAD>

</HEAD>

<BODY>

<?php

echo $crazy;

?>

</BODY>

</HTML>
?>
?>

When I click the Submit Button it just echos $dummie

What am I doing wrong?

Posted: Sat Feb 21, 2004 8:39 pm
by Albright
You only want your chunks of code inside <?php and ?>. Everything else (<BODY>, <HEAD>, etc) should not be inside a PHP block.

No offense, my man, but you've got to go back to the basics...

No Offense Taken But.....

Posted: Sat Feb 21, 2004 8:47 pm
by ut1205
The PHP button on the forum placed those tags there. I did not. My PHP tags are the internal ones.

Now that we're past that, can you tell me why my internal code does not work?

If I knew everything, I wouldn't be here in the first place!!!

Posted: Sat Feb 21, 2004 8:54 pm
by uberpolak
Your form tag needs to be inside <?php ?> tags for use of PHP variables, try this:

Code: Select all

<form action="passon2.php?crazy=<?php echo $dummie; ?>" method="post">

Thanks

Posted: Sat Feb 21, 2004 9:09 pm
by ut1205
Works great - Thanks. Sometimes you just look at things too long!!

Posted: Sat Feb 21, 2004 11:15 pm
by John Cartwright

Code: Select all

<?
echo "<form action="passon2.php" method="GET"\n".  
"<input type="hidden" name="last" value="$lastname"/> \n".
"</form>\n";
?>
Last time I tried something in the form action like page.php?variable=$variable it wouldnt work and I used hiddens to set the variable.