Passing variable data between php pages

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
Xyle
Forum Newbie
Posts: 2
Joined: Sat Feb 07, 2009 11:55 pm
Location: Nevada

Passing variable data between php pages

Post by Xyle »

I have 1 php page that when a user clicks an image it opens a new php page and passes a variable to the new page. The Problem Im having is that the variable is not getting passed.

Heres the code...

Code: Select all

            
$gCreatorArray[$tCnt] = $gCreator;
echo "<div style='Z-INDEX: 101; LEFT: 265px; WIDTH: 800px; POSITION: absolute; TOP: ".$tMarg2."px; HEIGHT: 20px'>";
echo "<form name='myform' action='http://localhost:8060/NWTTT/NWTTTClient2.php' method='POST'>";
echo "<input type='image' src='images/InvsBar500x20Red.png' name='image' value='".$gCreatorArray[$tCnt]."' width='500' height='20'>";
echo "GameCreator: ".$gCreatorArray[$tCnt];
echo "</form>";
echo "</div>";
 
I am tagging the image with "value = '".$gCreatorArray[$tCnt]."' but I dont understand why this isnt working, I even tried replacing the variable with 'woohoo' just to see if it would pass an actual string, but that didnt work either.

Any help would be greatly appreciated!!
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Re: Passing variable data between php pages

Post by deejay »

have you tried to var_dump the $_POST on the receiving page.

Code: Select all

 
var_dump($_POST);
 
what results does i give or is it null?
User avatar
dheeraj
Forum Commoner
Posts: 40
Joined: Fri Feb 06, 2009 11:54 am

Re: Passing variable data between php pages

Post by dheeraj »

why didn't u try anchor tag.....

here is the code

Code: Select all

$gCreatorArray[$tCnt] = $gCreator;
echo "<div style='Z-INDEX: 101; LEFT: 265px; WIDTH: 800px; POSITION: absolute; TOP: ".$tMarg2."px; HEIGHT: 20px'>";
echo "<a href='http://localhost:8060/NWTTT/NWTTTClient2.php?var1=$gCreatorArray[$tCnt]'><img src='images/InvsBar500x20Red.png' /></a>";
 
then in 2nd page receive value like below..

Code: Select all

$creater=$_GET['var1'];
tht's solve..
User avatar
Xyle
Forum Newbie
Posts: 2
Joined: Sat Feb 07, 2009 11:55 pm
Location: Nevada

Re: Passing variable data between php pages

Post by Xyle »

dheeraj wrote:why didn't u try anchor tag.....

here is the code

Code: Select all

$gCreatorArray[$tCnt] = $gCreator;
echo "<div style='Z-INDEX: 101; LEFT: 265px; WIDTH: 800px; POSITION: absolute; TOP: ".$tMarg2."px; HEIGHT: 20px'>";
echo "<a href='http://localhost:8060/NWTTT/NWTTTClient2.php?var1=$gCreatorArray[$tCnt]'><img src='images/InvsBar500x20Red.png' /></a>";
&nbsp;
then in 2nd page receive value like below..

Code: Select all

$creater=$_GET['var1'];
tht's solve..
Worked like a charm! Thank you very much!! I really appreciate the help. Deejay, thank you for your post, I didn't try the var_dump solution so I dont know if that would work or not, but thank you for the help also.
sharad99088
Forum Newbie
Posts: 2
Joined: Sun Feb 08, 2009 11:10 am

Re: Passing variable data between php pages

Post by sharad99088 »

your variable is not getting passed to next page because you form is not getting submitted. you can use the get method to pass the variable to next page on onclick event.
Post Reply