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
ut1205
Forum Commoner
Posts: 32 Joined: Thu Jan 29, 2004 5:12 pm
Post
by ut1205 » Sat Feb 21, 2004 7:28 pm
I have a defined variable lets call it:
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!!
uberpolak
Forum Contributor
Posts: 261 Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar
Post
by uberpolak » Sat Feb 21, 2004 7:35 pm
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
Post
by ut1205 » Sat Feb 21, 2004 7:59 pm
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?
uberpolak
Forum Contributor
Posts: 261 Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar
Post
by uberpolak » Sat Feb 21, 2004 8:16 pm
Is the variable in a string which is singlequoted? For example:
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
Post
by ut1205 » Sat Feb 21, 2004 8:32 pm
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?
Albright
Forum Newbie
Posts: 20 Joined: Sat Sep 13, 2003 8:03 pm
Contact:
Post
by Albright » Sat Feb 21, 2004 8:39 pm
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
Post
by ut1205 » Sat Feb 21, 2004 8:47 pm
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!!!
uberpolak
Forum Contributor
Posts: 261 Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar
Post
by uberpolak » Sat Feb 21, 2004 8:54 pm
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
Post
by ut1205 » Sat Feb 21, 2004 9:09 pm
Works great - Thanks. Sometimes you just look at things too long!!
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sat Feb 21, 2004 11:15 pm
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.