Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying PHP variables on a webpage 6

Status
Not open for further replies.

SteweGriffin

Technical User
Dec 16, 2009
14
0
0
GB
Hello,

I have a webform :-

<form action="job_load.php" method="post"
enctype="multipart/form-data" class="style2" style="width: 958px">
<span class="style34">
<label for="file"><td>Affilate Name:  
<img alt="" height="1" src="images/spacer.gif" width="64" class="style35" />
<input type="text" id="affilate" name="affilate" size="15" style="width: 149px" value="Your Trading Name"></td>
<br />
Job Loaders name:  
<img alt="" height="1" src="images/spacer.gif" width="25" class="style35" />
<input type="text" id="loadersname" name="loadersname" size="15" style="width: 149px" value="Your Full Name"></td>
<br />
Your e-Mail address:  
<img alt="" height="1" src="images/spacer.gif" width="13" class="style35" />
<input type="text" id="eaddress" name="eaddress" size="35" style="width: 263px" value="Your e-Mail address"></td>
<br />

Your
Clients Name:<img alt="" height="1" src="images/spacer.gif" width="38" class="style35" /><img alt="" height="10" src="images/spacer.gif" width="2" class="style35" />
<input type="text" id="cname" name="fullname" size="15" style="width: 229px" value="Your Clients Name / Trading Name"></td> 
<font face="verdana" size="2">Company Type:<img alt="" height="1" src="images/spacer.gif" width="6" class="style35" /><select name="cotype" size="1">
<option value="NotSelected">Select from below..</option>
<option value="Limited">Ltd</option>
<option value="Partnership">Partenership</option>
<option value="Sole Trader">Sole Trader</option>
<option value="N/A">Not Applicable</option>
</select></font><div><font face="verdana" size="2"><span class="style34">Type:</span><img alt="" height="1" src="images/spacer.gif" width="113" class="style35" /><select name="type" size="1">
<option value="NotSelected">Select from below..</option>
<option value="option1">1</option>
<option value="option2">3</option>
<option value="option3">3</option>
<option value="option4">4</option>
<option value="option5">5</option>
<option value="option6">6</option>
<option value="option7">7</option>
</select></div>
<div><span class="style34">Output Format requires:</span><img alt="" height="2" src="images/spacer.gif" width="13" class="style35" /><select name="format" size="1">
<option value="NotSelected">Select from below..</option>
<option value="option1">1</option>
<option value="option2">2</option>
<option value="option3">3</option>
<option value="option4">4</option>
<option value="option5">5</option>
<option value="option5">5</option>
<option value="OTHER-See Notes">OTHER - Please detail in the Notes section below.</option>
</select></div>

<span class="style34">Notes:</span><img alt="" height="1" src="images/spacer.gif" width="134" class="style35" />
<textarea cols="40" rows="7" wrap="virtual" name="message"></textarea>
<br/>
<span class="style37"><br />
<span class="style38">I confirm I have read the <a href="TermsAndConditions.html">Terms and
Conditions</a> and am sending all relevant documenting to enable completion
of the requested job. <br />
I acknowledged and any missing items may incure an addtional cost.</span> <input type="checkbox" name="confirm"></span><br />
<!--Filename:<img alt="" height="1" src="images/spacer.gif" width="62" class="style35" /></label></span>
<input type="file" name="file" id="file" size="50" style="width: 406px" /> -->
<br />
<p style="height: 40px"></p>
<div class="style1">
<input type="submit" name="submit" value="Submit Job" style="color: #FFFFFF; background-color: #000000; background-image: url('images/btnbck.gif'); border-color: #000000" />
</div>
</form>

Which parses the information to another PHP file (job_load.php):-

<?php
$affilate = $_POST['affilate'];
$type = $_POST['type'];
$cotype = $_POST['cotype'];
$loader = $_POST['loadersname'];
$client = $_POST['fullname'];
$eaddress = $_POST['eaddress'];
$sendTo = "email@emailaddress.co.uk"; // Set a variable that will be used for emailing
$subject = "A ".$type ." job has been submitted via the webpage by ".$loader ." of ".$affilate ." for their client ".$client ." ".$cotype; // This is the subject that will appear in the email

header('Location: Loadsuccess.php');

session_start();

set($_SESSION['user']);


$body = "------------------------------------------------------------------------------------------------\r\n";
$body .= "----------- The following job has been uploaded via webpage. -----------\r\n";
$body .= "------------------------------------------------------------------------------------------------\r\n";
$body .= "Affilate's name : ". $_POST['affilate'] .".\r\n";
$body .= "".$_POST['loadersname']." quoted their client as : ". $_POST['fullname'] ." (". $_POST['cotype'] .").\r\n";
$body .= "type is : ". $_POST['type'] .".\r\n";
$body .= "using : ". $_POST['program'] .".\r\n";
$body .= "The assocated message is : ". $_POST['message'] .".\r\n";
$body .= "Terms and Conditions etc have been tick (ON = yes) : ". $_POST['confirm'] .".\r\n";
$body .= "------------------------------------------------------------------------------------------------\r\n";
$body .= "---------------------------- Uploader's IP address was : ". $_SERVER['REMOTE_ADDR'] . " ------------------------\r\n";
$body .= "------------------------------------------------------------------------------------------------\r\n";

/* headers used to show from field in email client */
$headers = 'From: '.$eaddress."\r\n" .

'Reply-To: '.$eaddress;

/* this actually sends the mail */
mail($sendTo, $subject, $body, $headers);

?>

This, in turn ,opens loadsuccess.php, which is just a thank you page. This page opens up another on load :-

<script>
var theURL = 'coversheet.php';
var width = 400;
var height = 600;
function popWindow() {
newWindow = window.open(theURL,'newWindow','toolbar=no,menubar=no,resizable=no,scrollbars=no,status=no,location=no,width='+width+',height='+height);
}
</script>
<body onload="popWindow()">

Now, this is the code/page i'm having the trouble with
(coversheet.php) :-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<title>Accounts To You - CoverSheet</title>
<Script language="JavaScript" src="js/security.js"></script>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var newwindow;
function poptastic(url)
{
newwindow=window.open(url,'name','height=370,width=600,scrollbars=yes,resizable=yes,status=no');
}
</script>
<style type="text/css">
.style1 {
font-family: Arial, Helvetica, sans-serif;
}
.style2 {
font-family: Arial, Helvetica, sans-serif;
font-size: large;
}
.style3 {
font-family: Arial, Helvetica, sans-serif;
font-size: medium;
}
.style4 {
color: #5F860B;
}
.style5 {
font-family: Arial, Helvetica, sans-serif;
font-size: small;
}
</style>
</head>

<body>

<p> </p>
<p class="style2"><strong><span class="style4">Your</span> Coversheet</strong></p>
<p class="style5">(Insert this cover sheet to the front of each set of documents file you wish
to have scanned)</p>
<p class="style1"> </p>
<p class="style1"> </p>
<p class="style2"><?php $_POST['affilate']?></p>
<p class="style2"><?php $_POST['fullname']?><?php $_POST['cotype']?></p>
<p class="style2">Job type: <script language="javascript"> writeDateLong(6);</script></p>
<p class="style1"> </p>
<p class="style3">Contact at <?php $_POST['affilate']?> : <?php $_POST['loadersname']?></p>

</body>
<script language="JavaScript">
<!--
window.print();
//-->
</script>
</html>

The "coversheet" page loads, but but the $_POST variable and the "DateLong" do you get outputted ( or they do, but thay have a null value ).

I assuming this is a "school boy" error as I am fairly new to PHP, so any help correctly this would be great.

Thank in advance
 
Code:
Contact at <?php $_POST['affilate']?> : <?php $_POST['loadersname']?></p>

will not work instead

Code:
Contact at <?php [red]echo[/red] $_POST['affilate']?> : <?php [red]echo[/red] $_POST['loadersname']?></p>

the writeDateLong(6) is not a javascript built in command. assumedly you have a library somewhere that has this function in it. alternatively replace the code with the php equivalent (for (d)d/(m)m/yyyy) format)

Code:
<?php echo date('j/n/Y'); ?>
 
Hi jpadie,
Thanks for the advice.
The Date coding works a treat, Thanks, but the variables are still not echoing on the screen.

Any other ideas where I'm going wrong ?

Thanks again
 
Try inserting a dump_var($_POST) at a stratigic location to see if the post data is actualy getting set.

obviously it needs to be removed once you have resolved your issue & the site goes into production.
 
I agree with IPGuru. If nothing is coming out (source code or displayed) then the variables are not set.
 
Hi IPGuru and jpadie,

I put <? Php var_dump($_POST)?> and got array(0) { } , so it looks like i'm not parsing the variables correctly.

Any ideas what I can do to resolve this ?

Thanks
 
When you call your popWindow() function, the POST data is gone. You could either change the URL to include the variables and use GET
Code:
var theURL = 'coversheet.php?fullname=<?php echo $_POST['fullname']?>';
Or you might be able to change your popWindow function to submit a form with your values set.

-----------------------------------------
I cannot be bought. Find leasing information at
 
Hi Jaxtell,
I tried

var theURL = 'coversheet.php?fullname=<?php echo $_POST['fullname']?>';

but I still get

array(0) { }

and no information displayed.
Any Other ideas ? ( I did change coversheet.php to Echo fullname, rahter than echo <? php $_POST['fullname']?>.

Cheers
 
Hi, I hadn't changed that.
I have now, and I get

array(1) { ["fullname"]=> string(0) "" }
 
Ok then. That means the page that has
Code:
var theURL = 'coversheet.php?fullname=<?php echo $_POST['fullname']?>';
doesn't have a value for $_POST['fullname']. Make sure the values get passed to that page via POST or GET and adjust the code accordingly.

-----------------------------------------
I cannot be bought. Find leasing information at
 
You are moving over 4 different pages. Then moment you leave job_load.php (which is the only page that receives the posted information) the POST variable looses all posted information.

If you want to preserve all this data through the pages you can use Session variables, or some other method of storage.

As it is there is no way your posted values will available after you have loaded to other pages in between.

You could of course send all the values through the query string, and then retrieve them through the GET super global instead of POST.

Or even better attempt to do all the processing in a single page, instead of going around different pages.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Vacunita has the right idea. You should probably consider changing your design to better suit your needs. Something along the lines of the first page posting to the second, which could be a combination of job_load and loadsuccess. That way it would still have the POST variables that you could convert to GET for use in the popup.

first page stay the same
job_load.php becomes
Code:
<?php
$affilate = $_POST['affilate'];
$type = $_POST['type'];
$cotype = $_POST['cotype'];
$loader = $_POST['loadersname'];
$client = $_POST['fullname'];
$eaddress = $_POST['eaddress'];
$sendTo = "email@emailaddress.co.uk"; // Set a variable that will be used for emailing
$subject = "A ".$type ." job has been submitted via the webpage by ".$loader ." of ".$affilate ." for their client ".$client ." ".$cotype; // This is the subject that will appear in the email

   
    
    session_start();

     set($_SESSION['user']);

    
            $body = "------------------------------------------------------------------------------------------------\r\n";
            $body .= "----------- The following job has been uploaded via webpage. -----------\r\n";
            $body .= "------------------------------------------------------------------------------------------------\r\n";
            $body .= "Affilate's name : ". $_POST['affilate'] .".\r\n";
            $body .= "".$_POST['loadersname']." quoted their client as : ". $_POST['fullname'] ." (". $_POST['cotype'] .").\r\n";
            $body .= "type is : ". $_POST['type'] .".\r\n";
            $body .= "using : ". $_POST['program'] .".\r\n";
            $body .= "The assocated message is : ". $_POST['message'] .".\r\n";
            $body .= "Terms and Conditions etc have been tick (ON = yes) : ". $_POST['confirm'] .".\r\n";
            $body .= "------------------------------------------------------------------------------------------------\r\n";
            $body .= "---------------------------- Uploader's IP address was : ". $_SERVER['REMOTE_ADDR'] .  " ------------------------\r\n";
            $body .= "------------------------------------------------------------------------------------------------\r\n";
          
              /* headers used to show from field in email client */
            $headers = 'From: '.$eaddress."\r\n" .

                'Reply-To: '.$eaddress; 
            
            /* this actually sends the mail */
            mail($sendTo, $subject, $body, $headers);

?> 

<script>
var theURL = 'coversheet.php?fullname=<?PHP echo $_POST['fullname'];?>&affiliate=<?PHP echo $_POST['affiliate'];?>';//and so on
var width  = 400;
var height = 600;
function popWindow() {
newWindow = window.open(theURL,'newWindow','toolbar=no,menubar=no,resizable=no,scrollbars=no,status=no,location=no,width='+width+',height='+height);
}
</script>
<body onload="popWindow()">
then just change coversheet to use the $_GET superglobal instead of $_POST

-----------------------------------------
I cannot be bought. Find leasing information at
 
I would still suggest the session variables over GET if you must move around separate pages.

Code:
In job_load.php at the top of the page:
session_start();
$_SESSION['data']=$_POST;

then in ay other page you need to access to your posted data instead of referencing $_POST use $_SESSION['data'] such as:

Code:
session_start();
$affiliate=$_SESSION['data']['affiliate'];
That way you can keep all your posted info across different pages.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Hi Vacunita and Jaxtell,
Thanks for the great advise and help.

I thought i'd try Vacunitas way, do Job_Load.php looks like :-

<?php
$affilate = $_POST['affilate'];
$type = $_POST['type'];
$cotype = $_POST['cotype'];
$loader = $_POST['loadersname'];
$client = $_POST['fullname'];
$eaddress = $_POST['eaddress'];
$sendTo = "email@emailaddress.co.uk"; // Set a variable that will be used for emailing
$subject = "A ".$type ." job has been submitted via the webpage by ".$loader ." of ".$affilate ." for their client ".$client ." ".$cotype; // This is the subject that will appear in the email

header('Location: Loadsuccess.php');

session_start();

set($_SESSION['user']);
$_SESSION['data']=$_POST;

$body = "------------------------------------------------------------------------------------------------\r\n";
$body .= "----------- The following job has been uploaded via webpage. -----------\r\n";
$body .= "------------------------------------------------------------------------------------------------\r\n";
$body .= "Affilate's name : ". $_POST['affilate'] .".\r\n";
$body .= "".$_POST['loadersname']." quoted their client as : ". $_POST['fullname'] ." (". $_POST['cotype'] .").\r\n";
$body .= "type is : ". $_POST['type'] .".\r\n";
$body .= "using : ". $_POST['program'] .".\r\n";
$body .= "The assocated message is : ". $_POST['message'] .".\r\n";
$body .= "Terms and Conditions etc have been tick (ON = yes) : ". $_POST['confirm'] .".\r\n";
$body .= "------------------------------------------------------------------------------------------------\r\n";
$body .= "---------------------------- Uploader's IP address was : ". $_SERVER['REMOTE_ADDR'] . " ------------------------\r\n";
$body .= "------------------------------------------------------------------------------------------------\r\n";

/* headers used to show from field in email client */
$headers = 'From: '.$eaddress."\r\n" .

'Reply-To: '.$eaddress;

/* this actually sends the mail */
mail($sendTo, $subject, $body, $headers);

?>



While coversheet.php now looks like this :-

<?php
session_start();
$affiliate=$_SESSION['data']['affiliate'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<title>CoverSheet</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var newwindow;
function poptastic(url)
{
newwindow=window.open(url,'name','height=370,width=600,scrollbars=yes,resizable=yes,status=no');
}
</script>
<style type="text/css">
.style1 {
font-family: Arial, Helvetica, sans-serif;
}
.style2 {
font-family: Arial, Helvetica, sans-serif;
font-size: large;
}
.style3 {
font-family: Arial, Helvetica, sans-serif;
font-size: medium;
}
.style4 {
color: #5F860B;
}
.style5 {
font-family: Arial, Helvetica, sans-serif;
font-size: small;
}
</style>
</head>

<body>

<p>&nbsp;</p>
<p class="style2"><strong><span class="style4">Your</span> Scanning Cover Sheet</strong></p>
<p class="style5">(Insert this cover sheet with documents)</p>
<p class="style1">&nbsp;</p>
<p class="style1">&nbsp;</p>
<p class="style2"><?php echo $affilate?></p>
<p class="style2"><?php echo $_POST['fullname']; ?><?php echo $_POST['cotype']?></p>
<p class="style2">Job type: <?php echo date('d/m/Y'); ?></p>
<p class="style1">&nbsp;</p>
<p class="style3">Contact at <?php echo $_POST['affilate']?> : <?php echo $_POST['loadersname']?></p>
</body>
<script language="JavaScript">
<!--
window.print();
//-->
</script>
</html>

I only changed one variable, to see what happened, but Nothing came out.

Have I made another silly mistake ?

Thanks
 
Two things. I think you want the header function to be the last call in job_load. Check your spelling. One place you're using affilate, another it's affiliate.

-----------------------------------------
I cannot be bought. Find leasing information at
 
D'oh!

Darn spelling. Thanks Jaxtell.

I've sorted that out, and moved

$_SESSION['data']=$_POST;

to the end of job_load.php, do it now reads

mail($sendTo, $subject, $body, $headers);

$_SESSION['data']=$_POST;
?>

Still nothing appearing when I call contactsheet.php
 
Put the $_SESSION back at the top, where it was.

and remove the line: set($_SESSION['user']);

That should get it to work.

You are only echoing out affiliate though. So you'll only see that.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top