Info won't pass from 1st script to 3rd script

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
summitweb
Forum Commoner
Posts: 27
Joined: Thu Jun 30, 2005 4:28 am
Location: Atlanta, Georgia

Info won't pass from 1st script to 3rd script

Post by summitweb »

Hello:

I could use some guidance or help. This is what I'm trying to accomplish. I want to store a persons billing and shipping information in a table.

I have a form where the person enters their billing info. If the shipping info is the same as the billing info, they can check a checkbox.

When they submit the form, the billing info and shipping info appear. In addition, there is another form where they enter other information.

When they submit this form, the billing and shipping info does not come across.

How do I pass form variables from the first script to the third script? I am using sessions. The data passes from script 1 to script 2 but the data does not pass from script 2 to script 3.

I pasted the code for script 2 and 3 since script 1 is basically a form. Though, I will paste the line for the checkbox from this script.

Thank you in advance.

Script 1 - entry form with checkbox

Code: Select all

<tr>
    <td width="109" height="20">
      <div align="left"><font face="Verdana" size="1">If same as Billing:</font></div>
    </td>
    <td width="156" height="20">
      <font face="Verdana">
      <input type="checkbox" name="same"></font><font size="2" face="Verdana">
      </font>
    </td>
  </tr>
Script 2 - verifies info and processes another form

Code: Select all

<?php
session_start();
//connect to the database
$conn = mysql_connect("xx", "xx", "xx") 
  or die (mysql_error());
mysql_select_db("xx");
if ($_POST['same'] == 'on') {
  $_POST['shipfirst'] = $_POST['firstname'];
  $_POST['shiplast'] = $_POST['lastname'];
  $_POST['shipadd1'] = $_POST['add1'];
  $_POST['shipadd2'] = $_POST['add2'];
  $_POST['shipcity'] = $_POST['city'];
  $_POST['shipstate'] = $_POST['state'];
  $_POST['shipzip'] = $_POST['zip'];
  $_POST['shipphone'] = $_POST['phone'];
  $_POST['shipemail'] = $_POST['email'];
}
?>
<html>
<head>
<title>Step 2 of 3 - Verify Order Accuracy</title>
</head>
<body>
Step 1 - Please Enter Billing and Shipping Information<br>
<strong>Step 2 - Please Verify Accuracy and Make Any Necessary
     Changes</strong><br>
Step 3 - Order Confirmation and Receipt<br>

<form method="post" action="echo.php">
<table border="0" cellpadding="0" cellspacing="0" width=787>
  <tr>
    <td width=358><b><font size=2 face=Verdana>Bill to:</font></b></td>
    <td width=419><b><font size=2 face=Verdana>Ship to:</font></b></td>
  </tr>
  <tr>
    <td width=358><font size=2 face=Verdana><? echo "$_POST[firstname]  $_POST[lastname]"; ?></font></td>
    <td width=358><font size=2 face=Verdana><? echo "$_POST[firstname]  $_POST[lastname]"; ?></font></td>
  </tr>
  <tr>
    <td width=358><font face="Verdana" size="2"><? echo "$_POST[add1]"; ?></font></td>
    <td width=358><font face="Verdana" size="2"><? echo "$_POST[add1]"; ?></font></td>
  </tr>
  <tr>
    <td width=358><font size=2 face=Verdana><? echo "$_POST[add2]"; ?></font></td>
    <td width=358><font size=2 face=Verdana><? echo "$_POST[add2]"; ?></font></td>
  </tr>
  <tr>
    <td width=358><font size=2 face=Verdana><? echo "$_POST[city], $_POST[state],&nbsp;&nbsp; 
    $_POST[zip]"; ?></font></td>
    <td width=358><font size=2 face=Verdana><? echo "$_POST[city], $_POST[state],&nbsp;&nbsp; 
    $_POST[zip]"; ?></font></td>
  </tr>
  <tr>
    <td width=358>&nbsp;</td>
    <td width=358>&nbsp;</td>
  </tr>
  <tr>
    <td width=358><font face="Verdana" size="2"><? echo "$_POST[phone]"; ?></font></td>
    <td width=358><font face="Verdana" size="2"><? echo "$_POST[phone]"; ?></font></td>
  </tr>
  <tr>
    <td width=358><font face="Verdana" size="2"><? echo "$_POST[email]"; ?></font></td>
    <td width=358><font face="Verdana" size="2"><? echo "$_POST[email]"; ?></font></td>
  </tr>
  <tr>
    <td width=358>&nbsp;</td>
    <td width=419>&nbsp;</td>
  </tr>
  </table>

<hr>

<?php
$sessid = session_id();

$query = "SELECT * FROM carttemp WHERE carttemp_sess = '$sessid'";
$results = mysql_query($query) or die(mysql_error());
$rows = mysql_num_rows($results);
?>

<table border = "1" cellpadding="5">
  <tr>
     <td>Quantity</td>
     <td>Item Code</td>
     <td>Name</td>
     <td>Color</td>
     <td>Price</td>
     <td>Extended Price</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>

<?php
$total = 0.0;
$ordertotal = 0.0;

while ($row = mysql_fetch_array($results)) {
extract($row);

echo "<tr><td>";
echo $carttemp_qty;
echo "</td>";

echo "<td>";
echo "$carttemp_prodnum";
echo "</td>";

echo "<td>";
echo "$carttemp_prodname";
echo "</td>";

echo "<td>";
echo "$carttemp_color";
echo "</td>";

echo "<td>";
echo "$carttemp_price";
echo "</td>";

echo "<td align=\"right\">";

$extprice = $carttemp_price * $carttemp_qty;
$orderextprice = $carttemp_price * $carttemp_qty;

echo number_format($extprice,2);
echo "</td>";

echo "<td>";
echo "<a href=\"cart.php\">Make Changes to Cart</a>";
echo "</td>";
echo "</tr>";
//add extended price to total
$total = $extprice + $total;
$ordertotal = $orderextprice + $ordertotal;

}
?>
<tr>
<td colspan="5" align="right">Subtotal:</td>
<td align="right"> <?php echo number_format($total, 2); ?></td>
<td></td>
<td></td>
</tr>
</table>





<input type="hidden" name="ordertotal" value="<?php echo $ordertotal; ?>">
<p>
  <input type="submit" name="Submit" value="Send Order -->">
</p>
</form>

</body>
</html>
Finally, the third script which should populate the table with the billing and shipping info and it doesn't:

Code: Select all

<?php
session_start();
//connect to the database - either include a connection variable file 
//or type the following lines:
$connect = mysql_connect("xx", "xx", "xx") 
  or die ("Hey loser, check your server connection.");
mysql_select_db("xx");

//Let's make the variables easy to access in our queries
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$firstname = $_POST['firstname'];
$add1 = $_POST['add1'];
$add2 = $_POST['add2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$shipfirst = $_POST['shipfirst'];
$shiplast = $_POST['shiplast'];
$shipadd1 = $_POST['shipadd1'];
$shipadd2 = $_POST['shipadd2'];
$shipcity = $_POST['shipcity'];
$shipstate = $_POST['shipstate'];
$shipzip = $_POST['shipzip'];
$shipstate = $_POST['shipstate'];
$shipphone = $_POST['shipphone'];
$shipemail = $_POST['shipemail'];
$total = $_POST['total'];
$sessid = session_id();
$today = date("Y-m-d");

//2) Insert Info into ordermain

$query3 = "INSERT INTO ordermain (
           ordermain_orderdate, ordermain_custnum,
           ordermain_shipfirst, ordermain_shiplast,
           ordermain_shipadd1, ordermain_shipadd2,
           ordermain_shipcity, ordermain_shipstate,
           ordermain_shipzip, ordermain_shipphone,
           ordermain_shipemail)
           VALUES (
           '$today',
           '$customers_custnum',
           '$shipfirst',
           '$shiplast',
           '$shipadd1',
           '$shipadd2',
           '$shipcity',
           '$shipstate',
           '$shipzip',
           '$shipphone',
           '$shipemail')";
$insert2 = mysql_query($query3) or die (mysql_error());
$orderid = mysql_insert_id();
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

  1. your code would look better if it were in color :) (use

    Code: Select all

    tags)
    [*]although your second page has a form that could do the submittal, you don't generate [u]any[/u] form elements, but merely print the data in the elements from the first form.[/list]
summitweb
Forum Commoner
Posts: 27
Joined: Thu Jun 30, 2005 4:28 am
Location: Atlanta, Georgia

Post by summitweb »

Hi,

Thanks for the reply.

The second form does submit an element. It's a numeric value. You don't see it referenced in the third script because if I pasted any more code I was going to reach my character limit.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

okay.. so you have ordertotal. You're only sending that to the third form, nothing more. Look at the source code the second page generates. Notice how there aren't any other form elements for the other data?
summitweb
Forum Commoner
Posts: 27
Joined: Thu Jun 30, 2005 4:28 am
Location: Atlanta, Georgia

Post by summitweb »

Hi,

Yes, I see what you are saying. So, how do I get data which was posted from the first script into the third script?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

create new hidden fields for each (insecure), use sessions (more secure), store in a database (fairly secure)
summitweb
Forum Commoner
Posts: 27
Joined: Thu Jun 30, 2005 4:28 am
Location: Atlanta, Georgia

Post by summitweb »

Let me try this on for size.

My first script posts all the elements to the second script.

In my second script should I have something like this:

Code: Select all

<?php
session_start();
//connect to the database
$conn = mysql_connect("localhost", "summitw1", "fish2FRY9") 
  or die (mysql_error());
mysql_select_db("summitw1");
if ($_POST['same'] == 'on') {
  $_POST['shipfirst'] = $_POST['firstname'];
  $_POST['shiplast'] = $_POST['lastname'];
  $_POST['shipadd1'] = $_POST['add1'];
  $_POST['shipadd2'] = $_POST['add2'];
  $_POST['shipcity'] = $_POST['city'];
  $_POST['shipstate'] = $_POST['state'];
  $_POST['shipzip'] = $_POST['zip'];
  $_POST['shipphone'] = $_POST['phone'];
  $_POST['shipemail'] = $_POST['email'];
}

$_SESSION[firstname] = $_POST['firstname'];
$_SESSION[lastname] = $_POST['lastname'];
etc..etc..
$_SESSION[shipfirst] = $_POST['shipfirst'];
?>
Am I anywhere close?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yep. Just make sure to quote your named indices :)
summitweb
Forum Commoner
Posts: 27
Joined: Thu Jun 30, 2005 4:28 am
Location: Atlanta, Georgia

Post by summitweb »

Hi,

I just tested my theory which I passed by you. And guess what, it worked. Funny that!

Thanks for the help. :D
Post Reply