How to make the variable cross pages effectively

I'm sending some data from a variable that is retrieved successfully in a previous page and I need it to be part of a value of a submit, since I need it to use the value in another page and I'm sending it from a form, but for some reason the value is not going...

I can't seem to make this work:

<?php $programa1 = $dados[1]['link']; ?>                                
<form action="oucaGeral.php" method="post">
<input type="hidden" value='<?php echo $programa1; ?>'>
 <input type="image" src="Toolbar Music.png" alt="Submit button" width="31" height="31">
 </form>
doRodrigoAsked:
Who is Participating?
 
benschwartzConnect With a Mentor Commented:
Doh! it slipped by me:

      <param name='fileName' value="<?php $passThroughVar;?>">

should be

      <param name='fileName' value="<?php print $passThroughVar;?>">

and

      src="<?php $_POST['programa1'];?>" width=240 height=30 autostart=1 loop=0

should be

      src="<?php print $_POST['programa1'];?>" width=240 height=30 autostart=1 loop=0
0
 
benschwartzCommented:
give your hidden field a name:

<input type="hidden" name="passThroughVar" value='<?php echo $programa1; ?>'>

now in the oucaGeral.php script you can access it by your hidden field's name:

$passThroughVar = $_POST['passThroughVar'];
0
 
ramelongCommented:
You need to assign a name (see the snippet)...
Then you can catch this by $_POST['ExpectedVariable'] inside the programa1

<input type="hidden" name="ExpectedVariable" value="'<?php echo $programa1; ?>'" />

Open in new window

0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
doRodrigoAuthor Commented:
benschwartz:Yep I thought that you would be right and changed it, but it still didn't work. I attached the files the one that sends the variable and the one that receives it... Cheers!

 
FILE1.PHP
-----------------------------------------------
<?php

	$connection = mysql_connect("localhost","user_name","password");
	if(!$connection){
		die("Database connection failed: ".mysql_error());
	}
	
	$db_select = mysql_select_db("database_name",$connection);
	if(!$db_select){
		die("Database selection failed: ".mysql_error());
	}
	$count = 0;
	$result = mysql_query("SELECT * FROM tbLinks ORDER BY id DESC", $connection);
	while($row = mysql_fetch_array($result)){
		if($count<4){
		$count++;
		$dados[$count] = array('id'=>$row[0],'dia'=>$row[1],'mes'=>$row[2], 'ano'=>$row[3], 'programa'=>$row[4], 'resumo'=>$row[5], 'numero'=>$row[6], 'aprovado'=>$row[7],  'link'=>$row[8]);
		}
	}
		
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Esporte na Rede Programas Postados</title>
<style type="text/css">
<!--
	body {
	background-image: url(imgs/fundo2.gif);
	}
	.espaco{
		width: 800px;
		height: 70PX;
		padding: 15px;
		color: white;
		font-family: arial;
		position: relative; 
		top: 15px; 
		margin-left: auto;
		margin-right: auto;
	}
	.headerMain{
		background-color: black;
		width: 800px;
		height: 30PX;
		padding: 15px;
		color: white;
		font-family: arial;
		position: relative; 

		margin-left: auto;
		margin-right: auto;
	}
	.headerProg{
		background-color: orange;
		width: 800px;
		height: 110PX;
		padding: 15px;
		color: white;
		font-family: arial;
		-moz-border-radius-topright: 30px;
		-moz-border-radius-topleft: 30px;
		position: relative; 

		margin-left: auto;
		margin-right: auto;
	}
	.body{
		background-color: orange;
		width: 800px;
		height: 220PX;
		padding: 15px;
		color: white;
		font-family: arial;
		position: relative; 
		margin-left: auto;
		margin-right: auto;		
	}
	.add{
		background-color: orange;
		width: 800px;
		height: 70PX;
		padding: 15px;
		color: white;
		font-family: arial;
		position: relative; 

		margin-left: auto;
		margin-right: auto;		
	}
	.footer{
		background-color: orange;
		width: 800px;
		height: 50PX;
		padding: 15px;
		color: white;
		font-family: arial;		
		position: relative; 

		margin-left: auto;
		margin-right: auto;	
		-moz-border-radius-bottomright: 30px;
		-moz-border-radius-bottomleft: 30px;
	}
	input{
		font-size:10px;
		text-align:center;
		text-shadow:#ccc 1px 1px;
	}
	
-->
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.js" >
</script>


<script type="text/javascript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

  <script>
  $(document).ready(function() {
    $("#emailDialog").dialog(
	{ autoOpen: false,
		modal: true	}
	);
	$("#sendMailBtn").click(function(){
		$("#emailDialog").dialog('open');
	});
  });
  </script>
  <style type="text/css">
<!--
.style1 {
	color: #FFFFFF;
	font-weight: bold;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size:x-small;
}
.style2 {
	color: #FFFFFF;
	font-weight: bold;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: x-small;
}
body,td,th {
	color: #FFF;
}
.style3 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: xx-small;
}
a:link {
	color: #FFFFFF;
}
a:visited {
	color: #FFFFFF;
}
a:hover {
	color: #FFFFFF;
}
a:active {
	color: #FFFFFF;
}

-->
  </style>
</head>

<body onLoad="MM_preloadImages('../Site/footer1b.png','../Site/footer2b.png','../Site/footer3b.png','../Site/footer4b.png')" style="font-size:62.5%;">
<div align="center">
  <table width="925" border="0">
    <tr>
      <td><div align="center"></div></td>
    </tr>
    <tr valign="top" style="background: url(imgs/EsporteNaRedePP.png) no-repeat;">
      <td><div align="center">
        <table width="100%" height="89" border="0">
          <tr>
            <td height="83"><img src="imgs/space.png" width="157" height="76" border="0" usemap="#Map"></td>
            <td>&nbsp;</td>
            <td><div align="right"><img src="imgs/space.png" alt="" width="76" height="76" border="0" usemap="#Map2"></div></td>
          </tr>
        </table>
        <p>&nbsp;</p>
        <table width="100%" border="0">
          <tr>
            <td width="61%" height="152"><table width="95%" border="0">
              <tr>
                <td width="9%">&nbsp;</td>
                <td width="38%">                	
		                <table width="100%" border="0">
                          <tr>
                            <td width="57%"><span class="style3"><strong>Data</strong>: <?php echo $dados[1]['dia']."/".$dados[1]['mes']."/".$dados[1]['ano'];?></span></td>
                            <td width="43%"><span class="style3"><strong>Número</strong>: <?php echo $dados[1]['numero'];?></span></td>
                          </tr>
                          <tr>
                            <td colspan="2"><span class="style3"><strong>Resumo</strong>: <?php echo utf8_encode($dados[1]['resumo']);?></span></td>
                          </tr>
                          <tr>
                            <td colspan="2">
                            <div align="center">
                            	<?php $programa1 = $dados[1]['link']; 
                                ?>
                                
                            	<form action="oucaGeral.php" method="post">
                                	<input type="hidden" id="programa1" name="programa1" value='<?php echo $programa1; ?>'>
                                    <input type="image" src="Toolbar Music.png" alt="Submit button" width="31" height="31">
                                 </form>   
                            </div>                       		
                            </td>
                          </tr>
                        </table>
                    <p>&nbsp;</p></td>
                <td width="8%">&nbsp;</td>
                <td width="38%" valign="top"><table width="100%" border="0">
                  <tr>
                    <td width="57%"><span class="style3"><strong>Data</strong>: <?php echo $dados[2]['dia']."/".$dados[2]['mes']."/".$dados[3]['ano'];?></span></td>
                    <td width="43%"><span class="style3"><strong>Número</strong>: <?php echo $dados[2]['numero'];?></span></td>
                  </tr>
                  <tr>
                    <td colspan="2"><span class="style3"><strong>Resumo</strong>: <?php echo utf8_encode($dados[2]['resumo']);?></span></td>
                  </tr>
                </table></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td><table width="100%" border="0">
                  <tr>
                    <td width="57%"><span class="style3"><strong>Data</strong>: <?php echo $dados[3]['dia']."/".$dados[3]['mes']."/".$dados[3]['ano'];?></span></td>
                    <td width="43%"><span class="style3"><strong>Número</strong>: <?php echo $dados[3]['numero'];?></span></td>
                  </tr>
                  <tr>
                     <td colspan="2"><span class="style3"><strong>Resumo</strong>: <?php echo utf8_encode($dados[3]['resumo']);?></span></td>
                  </tr>
                </table></td>
                <td>&nbsp;</td>
                <td><table width="100%" border="0">
                  <tr>
                   <td width="57%"><span class="style3"><strong>Data</strong>: <?php echo $dados[4]['dia']."/".$dados[4]['mes']."/".$dados[4]['ano'];?></span></td>
                    <td width="43%"><span class="style3"><strong>Número</strong>: <?php echo $dados[4]['numero'];?></span></td>
                  </tr>
                  <tr>
                     <td colspan="2"><span class="style3"><strong>Resumo</strong>: <?php echo utf8_encode($dados[4]['resumo']);?></span></td>
                  </tr>
                </table></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td><p>&nbsp;</p>                  </td>
                <td>&nbsp;</td>
                <td><div align="right"><span class="style3">1 - 2 - 3 - 4</span></div></td>
              </tr>
            </table></td>
            <td width="31%" valign="top"><form name="form1" method="post" action="procuraEsporte.php">
                <br>
                <br>
                <table width="94%" border="0">
                  <tr>
                    <td colspan="2" align="center"><p class="style2"><img src="imgs/FormPPtext.png" width="224" height="27" align="middle"><br>
                    </p>                      </td>
                  </tr>
                  <tr>
                    <td width="53%" rowspan="2"><span class="style1">
                      <input type="radio" name="tipo" id="tipo" value="numero">
                      <img src="imgs/FormPPnumero.png" width="46" height="9"><br>
                      <input type="radio" name="tipo" id="tipo" value="data">
                      <img src="imgs/FormPPdata.png" width="28" height="9">                        <br>
                      <input type="radio" name="tipo" id="tipo" value="assunto">
                      <img src="imgs/FormPPassunto.png" width="48" height="9">                        </span></td>
                    <td width="47%">
                      <div align="center">
                        <input type="text" name="variavel" id="variavel" style="font-size:10px">
                        </div></td>
                  </tr>
                  <tr>
                    <td>
                      <div align="center">
                        <input type="submit" name="button" id="button" value="procurar" style="height:25px; width:80px">
                        <input type="hidden" name="programa" id="programa" value="EsporteNaRede"></div></td>
                  </tr>
                </table>
            </form></td>
            <td width="8%">&nbsp;</td>
          </tr>
        </table>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
</div></td>
    </tr>
    <tr>
      <td><div align="center"><br>
      </div></td>
    </tr>
    <tr>
      <td><div align="center">&nbsp;</div></td>
    </tr>
  </table>

</div>


<map name="Map2">
  <area shape="rect" coords="3,18,66,71" href="index.php">
</map>

<map name="Map">
  <area shape="rect" coords="19,13,137,70" href="EsporteNaRede.php">
</map>
</body>
</html>

-----------------------------------------------------
SECONDFILE.PHP

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Andante</title>

<style type="text/css">
body {
	background-image: url(imgs/fundo2.gif);
	background-repeat: repeat;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.js" ></script>

<script type="text/javascript">
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
</script>

<script src="Scripts/AC_ActiveX.js" type="text/javascript"></script>

<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>

</head>

<body>
<div align="center">
  <p align="left">    
<?php   $passThroughVar = $_POST['passThroughVar']; ?>
    <!-- begin embedded WindowsMedia file... -->
    <object id='mediaPlayer3737' width="240" height="50"
      classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95' 
      codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701'
      standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'>
      <param name='fileName' value="<?php $passThroughVar;?>">
      <param name='animationatStart' value='true'>
      <param name='transparentatStart' value='true'>
      <param name='autoStart' value="true">
      <param name='showControls' value="true">
      <param name='loop' value="false">
      <embed type='application/x-mplayer2'
      id='mediaPlayer3737'
      src="<?php $_POST['programa1'];?>" width=240 height=30 autostart=1 loop=0
      pluginspage="http://www.microsoft.com/Windows/MediaPlayer/download/default.asp"
      showcontrols=1 showdisplay=0 showstatusbar=1 > </embed>
    </object>
    <!-- end embedded WindowsMedia file... -->
  </p>
</div>
</body>
</html>

Open in new window

0
 
ramelongCommented:
@doRodrigo:
Can you explain what's the behavior you note?
SECONDFILE is invoqued?
Tray doing this in SECONDFILE (anywhere), in order to see the content of the sent variables...
0
 
doRodrigoAuthor Commented:
ramelong, the file sends the variable but it is not accessible... I know that the variable is avaiable in the first file and it is atributed to a hidden field and than it goes to the second file that should put the variable in the value field of a certain field you will notice on the second file, but the fact remains that the second file doesn't show the variable content in the value field...
0
 
benschwartzCommented:
in your FILE1.php, you have named your hidden field "programa1":

    <input type="hidden" id="programa1" name="programa1" value='<?php echo $programa1; ?>'>


in SECONDFILE.PHP you are attempting to capture "passThroughVar", the name from my example.

Update SECONDFILE.php to get "programa1" out of the POST array, and i've updated the variable name too:

    <?php   $programa1 = $_POST['programa1']; ?>

Also, when you use it to output your object tag, you are referencing both versions, so make them both the same:

      <param name='fileName' value="<?php $programa1;?>">
    ....
      src="<?php $programa1;?>" width=240 height=30 autostart=1 loop=0
0
 
ramelongCommented:
I noted that you are using "passThroughVar"...
Remember that the name you use in the hidden field is the same (case sensitive) you must use with the $_POST array...
I suggest you to use the following anywhere to see what are you receiving inside the $_POST array:

PS. is the snippet I forgot in the last comment..
<?php
print_r($_POST);
?>

Open in new window

0
 
doRodrigoAuthor Commented:
benschwartz and ramelong I just changed it into the right one:

It still doesn't work...

Here goes the code now that I changed it...

ramelong I did what you suggested and what I get is the following:

Array ( [programa1] => http://www.radiotube.org.br/upload/audio_anexo/8139c71a6c.mp3 [x] => 22 [y] => 16 )
oucageral.php
-----------------
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Andante</title>

<style type="text/css">
body {
	background-image: url(imgs/fundo2.gif);
	background-repeat: repeat;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.js" ></script>

<script type="text/javascript">
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
</script>

<script src="Scripts/AC_ActiveX.js" type="text/javascript"></script>

<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>

</head>

<body>
<div align="center">
  <p align="left">    
<?php   $passThroughVar = $_POST['programa1']; ?>
    <!-- begin embedded WindowsMedia file... -->
    <object id='mediaPlayer3737' width="240" height="50"
      classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95' 
      codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701'
      standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'>
      <param name='fileName' value="<?php $passThroughVar;?>">
      <param name='animationatStart' value='true'>
      <param name='transparentatStart' value='true'>
      <param name='autoStart' value="true">
      <param name='showControls' value="true">
      <param name='loop' value="false">
      <embed type='application/x-mplayer2'
      id='mediaPlayer3737'
      src="<?php $_POST['programa1'];?>" width=240 height=30 autostart=1 loop=0
      pluginspage="http://www.microsoft.com/Windows/MediaPlayer/download/default.asp"
      showcontrols=1 showdisplay=0 showstatusbar=1 > </embed>
    </object>
    <!-- end embedded WindowsMedia file... -->
  </p>
</div>
</body>
</html>

------------------------------------------------------------------

Open in new window

0
 
benschwartzCommented:
can you check the source on SECONDFILE.php and see if it is outputting the html you expect in that object tag?

The variable pass through looks like it is working now (however I don't know enough about embedding windowsmedia embeds to tell if the html you are generating is right)
0
 
ramelongCommented:
What data are you expecting in  <param name='fileName' value="<?php $passThroughVar;?>">  ?

You received the value "http://www.radiotube.org.br/upload/audio_anexo/8139c71a6c.mp3" into $_POST['programa1']. $_POST['x'] and $_POST['y'] are the coords fo the click on the image you use as submit botton.

Why you say that it doesn't work? The suggestion of Ben is a good one: Can you attach the source code of the generated HTML from the browser?
0
 
doRodrigoAuthor Commented:
Sure thing, here goes the generated HTML from the browser:

If you want to see the live result:

http://uerj.paginare.com.br/EsporteNaRedePP3.php

Just clink on the first and the only one that has an icon...

 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Andante</title>

<style type="text/css">
body {
	background-image: url(imgs/fundo2.gif);
	background-repeat: repeat;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.js" ></script>

<script type="text/javascript">
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
</script>

<script src="Scripts/AC_ActiveX.js" type="text/javascript"></script>

<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>

</head>

<body>
<div align="center">
  <p align="left">    
    <!-- begin embedded WindowsMedia file... -->
    <object id='mediaPlayer3737' width="240" height="50"
      classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95' 
      codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701'
      standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'>
      <param name='fileName' value="">
      <param name='animationatStart' value='true'>
      <param name='transparentatStart' value='true'>
      <param name='autoStart' value="true">
      <param name='showControls' value="true">
      <param name='loop' value="false">
      <embed type='application/x-mplayer2'
      id='mediaPlayer3737'
      src="" width=240 height=30 autostart=1 loop=0
      pluginspage="http://www.microsoft.com/Windows/MediaPlayer/download/default.asp"
      showcontrols=1 showdisplay=0 showstatusbar=1 > </embed>
    </object>
    <!-- end embedded WindowsMedia file... -->
  </p>
</div>
Array
(
    [programa1] => http://www.radiotube.org.br/upload/audio_anexo/8139c71a6c.mp3
    [x] => 12
    [y] => 8
)

</body>
</html>

Open in new window

0
 
doRodrigoAuthor Commented:
Yeah man that was it! It worked finally! Cheers and thanks a lot.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.