I am in the process of completing a php program. The issue i am having is getting the data to display on a page after submission so that the data can be printed and handed to the customers.
My current code is

<?php
if(isset($_POST['name'])) {
    $date = $_POST['date'];
    $name = $_POST['name'];
    $address = $_POST['address'];
    $tel = $_POST['telephone'];
    $cell = $_POST['cellphone'];
    $email = $_POST['email'];
    $equip = $_POST['equipment'];
    $manu = $_POST['manufacturer'];
    $model = $_POST['model'];
    $pri = $_POST['priority'];
    $notes = $_POST['notes'];

} 
?>
<table width="601" border="1" cellpadding="2">
  <tr>
    <td>Date:</td>
    <td width="181"><?php echo $msg; ?></td>
    <td width="82">Priority:</td>
    <td><?php echo $msg; ?></td>
  </tr>
  <tr>
    <td width="140">Customer Name:</td>
    <td colspan="2"><?php echo $name; ?></td>
    <td width="162">&nbsp;</td>
  </tr>
  <tr>
    <td>Address:</td>
    <td><?php echo $email; ?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>

</table>
<div id="disc">
</div>

<p> <button type="button" onclick="window.print();" >Print</button> | <a href="customer_device.html.php"><button type="button">Add New</button></a> </p>

This is code from the submission page

$q = "INSERT INTO customer (custid, date, custName, address1, address2, phone, cellphone, email, equipment, manufacturer, model, serial, imei, notes, priority) VALUES (' ', '$cd', '$cn','$ad1','$ad2','$p','$cp','$e', '$ty', '$mn', '$mo', '$sn', '$in', '$n', '$pr')";      
        $result = @mysqli_query ($dbcon, $q); // Run the query.
        if ($result) { // If it ran OK.
        header ("location: customer_device_print.html.php"); 
        exit();

Any help would be really appreciated.

on your submission script, instead of

if ($result) { // If it ran OK.
        header ("location: customer_device_print.html.php"); 
        exit();

you could use

if($result)  
        {  
           echo '<script type="text/javascript">
window.location = "customer_device_print.html.php?cell='.$cell; echo '"
</script>';
        }  

and then on customer_device_print.html.php use $cell = $_GET['cell']; then you can then run a mysql query to pull the data relevant to that cell number and echo the data throughout the page.

e.g

<?php 
$cell = $_GET['cell'];
$data = mysql_query("SELECT * FROM customer  WHERE cell='$cell' ") 
or die(mysql_error()); 
 while($info = mysql_fetch_array( $data ))

{ ?>


your page here 


<? } ?>

So I take it your redirect works alright, so all you need to do is:

<?php
$sql = "SELECT * FROM database WHERE ... "; #Query
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($query);
?>
<html>
<body onload="window.print()">

<h1>Order #<?= $row['orderID'] ?></h1> <!-- 'orderID' being the column in your DB -->
<hr />
<p>Some other content...</p>

</body>
</html>

Use a really simple HTML file to output the results, and the same idea works if you want to display a print page on your submission page. Just insert this code beneath the stuff you already have.

Thank you guys it worked ok

just a side note you can convert this: <?php echo $msg; ?>

to this <?=$msg?>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.