NewBee Question

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
ut1205
Forum Commoner
Posts: 32
Joined: Thu Jan 29, 2004 5:12 pm

NewBee Question

Post 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!!
User avatar
uberpolak
Forum Contributor
Posts: 261
Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar

Post 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.
ut1205
Forum Commoner
Posts: 32
Joined: Thu Jan 29, 2004 5:12 pm

Thanks but still the same problem

Post 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?
User avatar
uberpolak
Forum Contributor
Posts: 261
Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar

Post 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.
ut1205
Forum Commoner
Posts: 32
Joined: Thu Jan 29, 2004 5:12 pm

Here's the test script

Post 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?
User avatar
Albright
Forum Newbie
Posts: 20
Joined: Sat Sep 13, 2003 8:03 pm
Contact:

Post 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...
ut1205
Forum Commoner
Posts: 32
Joined: Thu Jan 29, 2004 5:12 pm

No Offense Taken But.....

Post 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!!!
User avatar
uberpolak
Forum Contributor
Posts: 261
Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar

Post 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">
ut1205
Forum Commoner
Posts: 32
Joined: Thu Jan 29, 2004 5:12 pm

Thanks

Post by ut1205 »

Works great - Thanks. Sometimes you just look at things too long!!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
Post Reply