Jump to content

sessions not setting -.-


aebstract

Recommended Posts

<?php
session_start();
header("Cache-control: private");
if(!isset($_SESSION["id"]))
{
header("Location: index.php?page=login");
}
if(!isset($_SESSION["cart"]))
{
header("Location: index.php?page=accounthome");
}

  $default = $_GET['default'];


if ($alternate == change){
$result = mysql_query("SELECT * FROM plants WHERE id='$id'") or DIE(mysql_error());

while($r=mysql_fetch_array($result))
{

$id=$r["id"];
$plantloc=$r["plantloc"];
$address=$r["address"];
$ph=$r["PH"];


}




if (isset ($_POST['submit2']))
{

$problem = FALSE;


      if (empty ($_POST['street'])) {
$problem = TRUE;
$error .= 'Street is a required field. <br />';
      }

      if (empty ($_POST['city'])) {
$problem = TRUE;
$error .= 'City is a required field. <br />';
      }

      if (empty ($_POST['state'])) {
$problem = TRUE;
$error .= 'State is a required field. <br />';
      }

      if (empty ($_POST['zip'])) {
$problem = TRUE;
$error .= 'Zip is a required field. <br />';
      }





if (!$problem) {

$_SESSION['city'] = ucwords($_POST['city']);
$_SESSION['state'] = strtoupper($_POST['state']);

$_SESSION['zip'] = $_POST['zip'];
$_SESSION['street'] = $_POST['street'];
$_SESSION['tempaddress'] = 1;

                      header("Location: index.php?page=checkout");


}

}




$content .= "
<p><u><a href=\"index.php?page=accounthome\">$plantloc</a></u> - Alternate Address </p>

<form action=\"index.php?page=checkout&alternate=change\" method=\"post\">
Street:<br />
<input type=\"text\" size=\"20\" name=\"street\" value=\"$_POST[street]\" /><br /><br />
<table><tr><td>
City:
</td><td>
State:
</td><td>
Zip:
</td></tr>
<tr><td>
<input type=\"text\" size=\"10\" name=\"city\" value=\"$_POST[city]\" />
</td><td>
<input type=\"text\" size=\"2\" name=\"state\" value=\"$_POST[state]\" />
</td><td>
<input type=\"text\" size=\"5\" name=\"zip\" value=\"$_POST[zip]\" />
</td></tr></table>
<br />
<input type=\"submit\" name=\"submit2\" class=\"textfield\" value=\"Submit Address\" />
</form>
";




} else {

$result = mysql_query("SELECT * FROM plants WHERE id='$id'") or DIE(mysql_error());
while($r=mysql_fetch_array($result))
{

$id=$r["id"];
$plantloc=$r["plantloc"];
$city=$r["city"];
$state=$r["state"];
$zip=$r["zip"];
$street=$r["street"];

}

$address = "$street<br />$city, $state - $zip";

if (isset($default)){
$_SESSION['tempaddress'] = 0;
header("Location: index.php?page=checkout");
}

if ($_SESSION['tempaddress'] == 1){
$displayaddress = "
$_SESSION[street]<br />
$_SESSION[city], $_SESSION[state] $_SESSION[zip]<br />
";
}



if (isset ($_POST['submit']))
{

$problem = FALSE;

      if (!isset($_POST['checktos'])) {
$problem = TRUE;
$error .= 'You must agree to the Terms of Service to complete your order. <br />';
      }

      if (empty ($_POST['ponumber'])) {
$problem = TRUE;
$error .= 'A PO number is required for checkout. <br />';
      }

      if (empty ($_POST['firstname'])) {
$problem = TRUE;
$error .= 'Your first name is required for checkout. <br />';
      }

      if (empty ($_POST['lastname'])) {
$problem = TRUE;
$error .= 'Your last name is required for checkout. <br />';
      }

      if (empty ($_POST['phonenumber1'])) {
$problem = TRUE;
$error .= 'Phone Number is a required field and all three blanks must be completed. <br />';
      } elseif (empty ($_POST['phonenumber2'])) {
$problem = TRUE;
$error .= 'Phone Number is a required field and all three blanks must be completed. <br />';
      } elseif (empty ($_POST['phonenumber3'])) {
$problem = TRUE;
$error .= 'Phone Number is a required field and all three blanks must be completed. <br />';
      }

if (!$problem) {

$ponumber = $_POST['ponumber'];
$shipping = $_POST['shipping'];
$notes = $_POST['notes'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$name = "$firstname $lastname";
$phonenumber1 = $_POST['phonenumber1'];
$phonenumber2 = $_POST['phonenumber2'];
$phonenumber3 = $_POST['phonenumber3'];
$telephone = "$_POST[phonenumber1]-$_POST[phonenumber2]-$_POST[phonenumber3]";

if (isset($default)){
$_SESSION['tempaddress'] = 0;
}

if ($_SESSION['tempaddress'] == 1){
$displayaddress = "
$_SESSION[street]<br />
$_SESSION[city], $_SESSION[state] $_SESSION[zip]<br />
";
}

$color1 = "#dddddd";
    $color2 = "#c0c0c0";
    $row_count = 0;

$parts .= "
<table width=732 cellpadding=3><tr bgcolor=#8d8d8d cellspacing=6><td width=10 align=center><b>LOC</b></td><td width=100><b>Part Number</b></td><td width=330><b>Description</b></td><td><b>Price</b></td><td><b>QTY</b></td></tr>";

$result2 = mysql_query("SELECT * FROM parts ORDER BY id ASC") or DIE(mysql_error());
while($r2=mysql_fetch_array($result2))
{
$pid=$r2["id"];
$loc=$r2["LOC"];
$pn=$r2["PN"];
$desc=$r2["DESC"];
$price=$r2["PRICE"];
$sub = $r2["SUB"];

$row_color = ($row_count % 2) ? $color1 : $color2;


$quan = ($_SESSION['cart'][$pid] < 1) ? "0" : $_SESSION['cart'][$pid];

if ($quan > 0){

if ($sub == 0){
$parts .= "<tr cellspacing=6><td align=center bgcolor=\"$row_color\">$loc</td><td bgcolor=\"$row_color\" width=\"100\">$pn</td><td bgcolor=\"$row_color\" width=\"330\">$desc</td><td bgcolor=\"$row_color\">$price</td><td bgcolor=\"$row_color\">$quan</td></tr>";
$row_count++;
} else {
$parts .= "<tr cellspacing=6><td align=center bgcolor=\"$row_color\">$loc-$sub</td><td bgcolor=\"$row_color\" width=\"100\">$pn</td><td bgcolor=\"$row_color\" width=\"330\">$desc</td><td bgcolor=\"$row_color\">$price</td><td bgcolor=\"$row_color\">$quan</td></tr>";
$row_count++;
}
$total = $total + ($price * $quan);

}



}
include "Rate.php5";

$parts .= "<tr cellspacing=6><td align=center></td><td></td><td align=right><B>TOTAL</B></td><td bgcolor=yellow>$total</td><td></td></tr></table>";


$datetime = date('m/d/Y - g:i A');


$result = MYSQL_QUERY("INSERT INTO orders (po,plantloc,address,telephone,name,notes,shipping,parts,datetime)".
"VALUES ('$ponumber', '$plantloc', '$address2', '$telephone', '$name', '$notes', '$shipping', '$parts', '$datetime')") or die (mysql_error());

$emailbody = "<font style=verdana>
<table width=732 cellpadding=3><tr bgcolor=#f3f3f3 cellspacing=6><td>
<u>$plantloc</u></td><td>$name - $telephone</td><tr><td>
$address2</td><td>

<table><tr><td align=right>
<b>PO #:</b>
</td><td>
$ponumber
</td></tr><tr><td align=right>
<b>Shipping:</b>
</td><td>
$shipping
</td></tr><tr><td align=right>
<b>Date:</b>
</td><td>
$datetime
</td></tr></table>

</td></tr></table>
<br />
   <u>Special Notes</u>
<table width=732 cellpadding=3 bgcolor=f3f3f3>
<tr><td>$notes</td></tr>
</table>
<br />
$parts<br /><br />
</font>
";


$to  = 'tcantwell@berryequipment.net' . ', '; // note the comma

// subject
$subject = 'Purchase Orders';

// message
$message = "
<html>
<head>
</head>
<body>
$emailbody
</body>
</html>
";

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Candace Painter <cpainter@berryequipment.net>' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);


                      header("Location: index.php?page=thankyou");





} }









$content .= "
<h1>Checkout</h1>
";

$color1 = "#dddddd";
    $color2 = "#c0c0c0";
    $row_count = 0;

$content .= "
<table width=732 cellpadding=3><tr bgcolor=#8d8d8d cellspacing=6><td width=10 align=center>LOC</td><td width=100>Part Number</td><td width=330>Description</td><td>Price</td><td>QTY</td></tr>";

$result2 = mysql_query("SELECT * FROM parts ORDER BY LOC ASC") or DIE(mysql_error());
while($r2=mysql_fetch_array($result2))
{
$pid=$r2["id"];
$loc=$r2["LOC"];
$pn=$r2["PN"];
$desc=$r2["DESC"];
$price=$r2["PRICE"];
$sub=$r["SUB"];

$row_color = ($row_count % 2) ? $color1 : $color2;


$quan = ($_SESSION['cart'][$pid] < 1) ? "0" : $_SESSION['cart'][$pid];

if ($quan > 0){
if ($sub == 0) {
$content .= "<tr cellspacing=6><td align=center bgcolor=\"$row_color\">$loc</td><td bgcolor=\"$row_color\" width=\"100\">$pn</td><td bgcolor=\"$row_color\" width=\"330\">$desc</td><td bgcolor=\"$row_color\">$price</td><td bgcolor=\"$row_color\">$quan</td></tr>";
$row_count++;
} else {
$content .= "<tr cellspacing=6><td align=center bgcolor=\"$row_color\">$loc-$sub</td><td bgcolor=\"$row_color\" width=\"100\">$pn</td><td bgcolor=\"$row_color\" width=\"330\">$desc</td><td bgcolor=\"$row_color\">$price</td><td bgcolor=\"$row_color\">$quan</td></tr>";
$row_count++;
}
$total = $total + ($price * $quan);

}


}
$content .= "<tr cellspacing=6><td align=center></td><td></td><td></td><td bgcolor=yellow><b>$total</b></td><td></td></tr>";

if ($_SESSION['tempaddress'] == 1) {
$address2 = $displayaddress;
} else {
$address2 = $address;
}

$content .= "
<form action=\"index.php?page=checkout\" method=\"post\" name=\"checkout\">
<table>
<tr><td width=250 valign=top>
Shipping Address:<br />
$_SESSION[tempaddress]
<p>$address2</p><br />
<a href=index.php?page=checkout&alternate=change>Ship to alternate location</a>
<br />
<a href=index.php?page=checkout&default=true>Reset default address</a>
</td><td valign=top width=450>
First Name:<br />
<input type=\"text\" size=\"20\" name=\"firstname\" value=\"$_POST[firstname]\" /><br /><br />
Last Name:<br />
<input type=\"text\" size=\"20\" name=\"lastname\" value=\"$_POST[lastname]\" /><br /><br />
Shipping Method:<br />
<select name=shipping>
<option value=\"Ground\">Ground</option>\n
<option value=\"Expedite\">Expedite</option>\n
<option value=\"Expedite A.M.\">Expedite A.M.</option>\n
<option value=\"Expedite Saturday\">Expedite Saturday</option>\n
<option value=\"2 Day\">2nd Day</option>\n
<option value=\"3 Day\">3rd Day</option>\n
</select>
<br /><br />
PO Number:<br />
<input type=\"text\" size=\"20\" name=\"ponumber\" value=\"$_POST[ponumber]\" /><br /><br />
Contact Telephone #:<br />
<input type=\"text\" size=\"3\" onKeyup=\"autotab(this, document.checkout.phonenumber2)\" maxlength=3 name=\"phonenumber1\" value=\"$_POST[phonenumber1]\" />
<input type=\"text\" size=\"3\"  onKeyup=\"autotab(this, document.checkout.phonenumber3)\" maxlength=3 name=\"phonenumber2\" value=\"$_POST[phonenumber2]\" />
<input type=\"text\" size=\"3\" maxlength=4 name=\"phonenumber3\" value=\"$_POST[phonenumber3]\" />
<br /><br />
Special Notes:<br />
<textarea cols=\"30\" rows=\"3\" name=\"notes\" value=\"$_POST[notes]\"></textarea>

</td></tr></table>

<p align=left><input type=\"checkbox\" name=\"checktos\" value=\"tos\"> I agree to the <a href=#>Terms of Service</a>.</p>
<p align=right><input type=\"submit\" name=\"submit\" class=\"textfield\" value=\"Checkout\" /></p>
</form>
";

}




?>

 

This is the entire checkout page, the part that is mostly being used that has the problem is the top section, where alternate=change. When they fill out the form for street, city, state and zip.. it should set the sessions accordingly, and then if the alternateaddress session is set to 1, it should read those session values as the new address. It's formatting it differently (since the formatting between the two is slightly different) even though it is formatting the way it should when address is changed, it's still using the stored address for the account. This script was working when I had it as two separate pages and once I combined and used an if to split it up so I could run it off the same file it started acting up.

Link to comment
Share on other sites

Craygo: Alternate is set in the url, alternate=change. If it wasn't set then the form to change the address wouldn't display cause of the if statement on line 18.

 

phpSensei: Alternate Var? no.. I don't think so. If I understand your question, see above sentance. $_SESSION['tempaddress'] = 1; gets set when the alternate address is submitted. When you're on the checkout page, it checks to see if that session is set to 0 or set to 1. If it is set to 1, it should be reading the newly entered address (saved as the sessions) and if not it should be reading the address from the database.

 

PFMaBiSmAd: I turned the errors on, got many errors. Some of which I believe are just from the form I have on the checkout page and the fields not having anything in them yet. Here are the errors that it displays:

 

Notice: A session had already been started - ignoring session_start() in /home/virtual/site21/fst/var/www/html/2/checkout.php on line 4

Notice: Undefined index: default in /home/virtual/site21/fst/var/www/html/2/checkout.php on line 17

Notice: Use of undefined constant change - assumed 'change' in /home/virtual/site21/fst/var/www/html/2/checkout.php on line 20

Notice: Undefined variable: total in /home/virtual/site21/fst/var/www/html/2/checkout.php on line 362

Notice: Undefined index: firstname in /home/virtual/site21/fst/var/www/html/2/checkout.php on line 388

Notice: Undefined index: lastname in /home/virtual/site21/fst/var/www/html/2/checkout.php on line 390

Notice: Undefined index: ponumber in /home/virtual/site21/fst/var/www/html/2/checkout.php on line 402

Notice: Undefined index: phonenumber1 in /home/virtual/site21/fst/var/www/html/2/checkout.php on line 404

Notice: Undefined index: phonenumber2 in /home/virtual/site21/fst/var/www/html/2/checkout.php on line 405

Notice: Undefined index: phonenumber3 in /home/virtual/site21/fst/var/www/html/2/checkout.php on line 406

Notice: Undefined index: notes in /home/virtual/site21/fst/var/www/html/2/checkout.php on line 409

Notice: Use of undefined constant id - assumed 'id' in /home/virtual/site21/fst/var/www/html/2/index.php on line 164
    Logout

Notice: Use of undefined constant id - assumed 'id' in /home/virtual/site21/fst/var/www/html/2/index.php

 

I also added the exit; statements and I understand that it is good to use, and will begin doing so (didn't solve problem though).

 

 

New code: (though not much changed, just what I stated above)

 

<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
session_start();
header("Cache-control: private");
if(!isset($_SESSION["id"]))
{
header("Location: index.php?page=login");
					exit;
}
if(!isset($_SESSION["cart"]))
{
header("Location: index.php?page=accounthome");
					exit;
}

  $default = $_GET['default'];


if ($alternate == change){
$result = mysql_query("SELECT * FROM plants WHERE id='$id'") or DIE(mysql_error());

while($r=mysql_fetch_array($result))
{

$id=$r["id"];
$plantloc=$r["plantloc"];
$address=$r["address"];
$ph=$r["PH"];


}




if (isset ($_POST['submit2']))
{

$problem = FALSE;


      if (empty ($_POST['street'])) {
$problem = TRUE;
$error .= 'Street is a required field. <br />';
      }

      if (empty ($_POST['city'])) {
$problem = TRUE;
$error .= 'City is a required field. <br />';
      }

      if (empty ($_POST['state'])) {
$problem = TRUE;
$error .= 'State is a required field. <br />';
      }

      if (empty ($_POST['zip'])) {
$problem = TRUE;
$error .= 'Zip is a required field. <br />';
      }





if (!$problem) {

$_SESSION['city'] = ucwords($_POST['city']);
$_SESSION['state'] = strtoupper($_POST['state']);

$_SESSION['zip'] = $_POST['zip'];
$_SESSION['street'] = $_POST['street'];
$_SESSION['tempaddress'] = 1;

                      header("Location: index.php?page=checkout");
					exit;

}

}




$content .= "
<p><u><a href=\"index.php?page=accounthome\">$plantloc</a></u> - Alternate Address </p>

<form action=\"index.php?page=checkout&alternate=change\" method=\"post\">
Street:<br />
<input type=\"text\" size=\"20\" name=\"street\" value=\"$_POST[street]\" /><br /><br />
<table><tr><td>
City:
</td><td>
State:
</td><td>
Zip:
</td></tr>
<tr><td>
<input type=\"text\" size=\"10\" name=\"city\" value=\"$_POST[city]\" />
</td><td>
<input type=\"text\" size=\"2\" name=\"state\" value=\"$_POST[state]\" />
</td><td>
<input type=\"text\" size=\"5\" name=\"zip\" value=\"$_POST[zip]\" />
</td></tr></table>
<br />
<input type=\"submit\" name=\"submit2\" class=\"textfield\" value=\"Submit Address\" />
</form>
";




} else {

$result = mysql_query("SELECT * FROM plants WHERE id='$id'") or DIE(mysql_error());
while($r=mysql_fetch_array($result))
{

$id=$r["id"];
$plantloc=$r["plantloc"];
$city=$r["city"];
$state=$r["state"];
$zip=$r["zip"];
$street=$r["street"];

}

$address = "$street<br />$city, $state - $zip";

if (isset($default)){
$_SESSION['tempaddress'] = 0;
header("Location: index.php?page=checkout");
}

if ($_SESSION['tempaddress'] == 1){
$displayaddress = "
$_SESSION[street]<br />
$_SESSION[city], $_SESSION[state] $_SESSION[zip]<br />
";
}



if (isset ($_POST['submit']))
{

$problem = FALSE;

      if (!isset($_POST['checktos'])) {
$problem = TRUE;
$error .= 'You must agree to the Terms of Service to complete your order. <br />';
      }

      if (empty ($_POST['ponumber'])) {
$problem = TRUE;
$error .= 'A PO number is required for checkout. <br />';
      }

      if (empty ($_POST['firstname'])) {
$problem = TRUE;
$error .= 'Your first name is required for checkout. <br />';
      }

      if (empty ($_POST['lastname'])) {
$problem = TRUE;
$error .= 'Your last name is required for checkout. <br />';
      }

      if (empty ($_POST['phonenumber1'])) {
$problem = TRUE;
$error .= 'Phone Number is a required field and all three blanks must be completed. <br />';
      } elseif (empty ($_POST['phonenumber2'])) {
$problem = TRUE;
$error .= 'Phone Number is a required field and all three blanks must be completed. <br />';
      } elseif (empty ($_POST['phonenumber3'])) {
$problem = TRUE;
$error .= 'Phone Number is a required field and all three blanks must be completed. <br />';
      }

if (!$problem) {

$ponumber = $_POST['ponumber'];
$shipping = $_POST['shipping'];
$notes = $_POST['notes'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$name = "$firstname $lastname";
$phonenumber1 = $_POST['phonenumber1'];
$phonenumber2 = $_POST['phonenumber2'];
$phonenumber3 = $_POST['phonenumber3'];
$telephone = "$_POST[phonenumber1]-$_POST[phonenumber2]-$_POST[phonenumber3]";

if (isset($default)){
$_SESSION['tempaddress'] = 0;
}

if ($_SESSION['tempaddress'] == 1){
$displayaddress = "
$_SESSION[street]<br />
$_SESSION[city], $_SESSION[state] $_SESSION[zip]<br />
";
}

$color1 = "#dddddd";
    $color2 = "#c0c0c0";
    $row_count = 0;

$parts .= "
<table width=732 cellpadding=3><tr bgcolor=#8d8d8d cellspacing=6><td width=10 align=center><b>LOC</b></td><td width=100><b>Part Number</b></td><td width=330><b>Description</b></td><td><b>Price</b></td><td><b>QTY</b></td></tr>";

$result2 = mysql_query("SELECT * FROM parts ORDER BY id ASC") or DIE(mysql_error());
while($r2=mysql_fetch_array($result2))
{
$pid=$r2["id"];
$loc=$r2["LOC"];
$pn=$r2["PN"];
$desc=$r2["DESC"];
$price=$r2["PRICE"];
$sub = $r2["SUB"];

$row_color = ($row_count % 2) ? $color1 : $color2;


$quan = ($_SESSION['cart'][$pid] < 1) ? "0" : $_SESSION['cart'][$pid];

if ($quan > 0){

if ($sub == 0){
$parts .= "<tr cellspacing=6><td align=center bgcolor=\"$row_color\">$loc</td><td bgcolor=\"$row_color\" width=\"100\">$pn</td><td bgcolor=\"$row_color\" width=\"330\">$desc</td><td bgcolor=\"$row_color\">$price</td><td bgcolor=\"$row_color\">$quan</td></tr>";
$row_count++;
} else {
$parts .= "<tr cellspacing=6><td align=center bgcolor=\"$row_color\">$loc-$sub</td><td bgcolor=\"$row_color\" width=\"100\">$pn</td><td bgcolor=\"$row_color\" width=\"330\">$desc</td><td bgcolor=\"$row_color\">$price</td><td bgcolor=\"$row_color\">$quan</td></tr>";
$row_count++;
}
$total = $total + ($price * $quan);

}



}
include "Rate.php5";

$parts .= "<tr cellspacing=6><td align=center></td><td></td><td align=right><B>TOTAL</B></td><td bgcolor=yellow>$total</td><td></td></tr></table>";


$datetime = date('m/d/Y - g:i A');


$result = MYSQL_QUERY("INSERT INTO orders (po,plantloc,address,telephone,name,notes,shipping,parts,datetime)".
"VALUES ('$ponumber', '$plantloc', '$address2', '$telephone', '$name', '$notes', '$shipping', '$parts', '$datetime')") or die (mysql_error());

$emailbody = "<font style=verdana>
<table width=732 cellpadding=3><tr bgcolor=#f3f3f3 cellspacing=6><td>
<u>$plantloc</u></td><td>$name - $telephone</td><tr><td>
$address2</td><td>

<table><tr><td align=right>
<b>PO #:</b>
</td><td>
$ponumber
</td></tr><tr><td align=right>
<b>Shipping:</b>
</td><td>
$shipping
</td></tr><tr><td align=right>
<b>Date:</b>
</td><td>
$datetime
</td></tr></table>

</td></tr></table>
<br />
   <u>Special Notes</u>
<table width=732 cellpadding=3 bgcolor=f3f3f3>
<tr><td>$notes</td></tr>
</table>
<br />
$parts<br /><br />
</font>
";


$to  = 'tcantwell@berryequipment.net' . ', '; // note the comma

// subject
$subject = 'Purchase Orders';

// message
$message = "
<html>
<head>
</head>
<body>
$emailbody
</body>
</html>
";

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Candace Painter <cpainter@berryequipment.net>' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);


                      header("Location: index.php?page=thankyou");
					exit;




} }









$content .= "
<h1>Checkout</h1>
";

$color1 = "#dddddd";
    $color2 = "#c0c0c0";
    $row_count = 0;

$content .= "
<table width=732 cellpadding=3><tr bgcolor=#8d8d8d cellspacing=6><td width=10 align=center>LOC</td><td width=100>Part Number</td><td width=330>Description</td><td>Price</td><td>QTY</td></tr>";

$result2 = mysql_query("SELECT * FROM parts ORDER BY LOC ASC") or DIE(mysql_error());
while($r2=mysql_fetch_array($result2))
{
$pid=$r2["id"];
$loc=$r2["LOC"];
$pn=$r2["PN"];
$desc=$r2["DESC"];
$price=$r2["PRICE"];
$sub=$r["SUB"];

$row_color = ($row_count % 2) ? $color1 : $color2;


$quan = ($_SESSION['cart'][$pid] < 1) ? "0" : $_SESSION['cart'][$pid];

if ($quan > 0){
if ($sub == 0) {
$content .= "<tr cellspacing=6><td align=center bgcolor=\"$row_color\">$loc</td><td bgcolor=\"$row_color\" width=\"100\">$pn</td><td bgcolor=\"$row_color\" width=\"330\">$desc</td><td bgcolor=\"$row_color\">$price</td><td bgcolor=\"$row_color\">$quan</td></tr>";
$row_count++;
} else {
$content .= "<tr cellspacing=6><td align=center bgcolor=\"$row_color\">$loc-$sub</td><td bgcolor=\"$row_color\" width=\"100\">$pn</td><td bgcolor=\"$row_color\" width=\"330\">$desc</td><td bgcolor=\"$row_color\">$price</td><td bgcolor=\"$row_color\">$quan</td></tr>";
$row_count++;
}
$total = $total + ($price * $quan);

}


}
$content .= "<tr cellspacing=6><td align=center></td><td></td><td></td><td bgcolor=yellow><b>$total</b></td><td></td></tr>";

if ($_SESSION['tempaddress'] == 1) {
$address2 = $displayaddress;
} else {
$address2 = $address;
}

$content .= "
<form action=\"index.php?page=checkout\" method=\"post\" name=\"checkout\">
<table>
<tr><td width=250 valign=top>
Shipping Address:<br />
$_SESSION[tempaddress]
<p>$address2</p><br />
<a href=index.php?page=checkout&alternate=change>Ship to alternate location</a>
<br />
<a href=index.php?page=checkout&default=true>Reset default address</a>
</td><td valign=top width=450>
First Name:<br />
<input type=\"text\" size=\"20\" name=\"firstname\" value=\"$_POST[firstname]\" /><br /><br />
Last Name:<br />
<input type=\"text\" size=\"20\" name=\"lastname\" value=\"$_POST[lastname]\" /><br /><br />
Shipping Method:<br />
<select name=shipping>
<option value=\"Ground\">Ground</option>\n
<option value=\"Expedite\">Expedite</option>\n
<option value=\"Expedite A.M.\">Expedite A.M.</option>\n
<option value=\"Expedite Saturday\">Expedite Saturday</option>\n
<option value=\"2 Day\">2nd Day</option>\n
<option value=\"3 Day\">3rd Day</option>\n
</select>
<br /><br />
PO Number:<br />
<input type=\"text\" size=\"20\" name=\"ponumber\" value=\"$_POST[ponumber]\" /><br /><br />
Contact Telephone #:<br />
<input type=\"text\" size=\"3\" onKeyup=\"autotab(this, document.checkout.phonenumber2)\" maxlength=3 name=\"phonenumber1\" value=\"$_POST[phonenumber1]\" />
<input type=\"text\" size=\"3\"  onKeyup=\"autotab(this, document.checkout.phonenumber3)\" maxlength=3 name=\"phonenumber2\" value=\"$_POST[phonenumber2]\" />
<input type=\"text\" size=\"3\" maxlength=4 name=\"phonenumber3\" value=\"$_POST[phonenumber3]\" />
<br /><br />
Special Notes:<br />
<textarea cols=\"30\" rows=\"3\" name=\"notes\" value=\"$_POST[notes]\"></textarea>

</td></tr></table>

<p align=left><input type=\"checkbox\" name=\"checktos\" value=\"tos\"> I agree to the <a href=#>Terms of Service</a>.</p>
<p align=right><input type=\"submit\" name=\"submit\" class=\"textfield\" value=\"Checkout\" /></p>
</form>
";

}




?>

Link to comment
Share on other sites

Okay, but read what I am trying to tell you. Yes that may be correct, and I did change it.. however, it is already letting me access my change address form. The problem is that it isn't setting the session variables to the correct values.. (and the change didn't fix it)

 

 

Maybe this error is significant?

Notice: A session had already been started - ignoring session_start() in /home/virtual/site21/fst/var/www/html/2/checkout.php on line 4

Link to comment
Share on other sites

The code I keep posting,

<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
session_start();
header("Cache-control: private");
if(!isset($_SESSION["id"]))
{
header("Location: index.php?page=login");
					exit;
}
if(!isset($_SESSION["cart"]))
{
header("Location: index.php?page=accounthome");
					exit;
}

  $default = $_GET['default'];


if ($alternate == change){
$result = mysql_query("SELECT * FROM plants WHERE id='$id'") or DIE(mysql_error());

while($r=mysql_fetch_array($result))
{

$id=$r["id"];
$plantloc=$r["plantloc"];
$address=$r["address"];
$ph=$r["PH"];


}




if (isset ($_POST['submit2']))
{

$problem = FALSE;


      if (empty ($_POST['street'])) {
$problem = TRUE;
$error .= 'Street is a required field. <br />';
      }

      if (empty ($_POST['city'])) {
$problem = TRUE;
$error .= 'City is a required field. <br />';
      }

      if (empty ($_POST['state'])) {
$problem = TRUE;
$error .= 'State is a required field. <br />';
      }

      if (empty ($_POST['zip'])) {
$problem = TRUE;
$error .= 'Zip is a required field. <br />';
      }





if (!$problem) {

$_SESSION['city'] = ucwords($_POST['city']);
$_SESSION['state'] = strtoupper($_POST['state']);

$_SESSION['zip'] = $_POST['zip'];
$_SESSION['street'] = $_POST['street'];
$_SESSION['tempaddress'] = 1;

                      header("Location: index.php?page=checkout");
					exit;

}

}




$content .= "
<p><u><a href=\"index.php?page=accounthome\">$plantloc</a></u> - Alternate Address </p>

<form action=\"index.php?page=checkout&alternate=change\" method=\"post\">
Street:<br />
<input type=\"text\" size=\"20\" name=\"street\" value=\"$_POST[street]\" /><br /><br />
<table><tr><td>
City:
</td><td>
State:
</td><td>
Zip:
</td></tr>
<tr><td>
<input type=\"text\" size=\"10\" name=\"city\" value=\"$_POST[city]\" />
</td><td>
<input type=\"text\" size=\"2\" name=\"state\" value=\"$_POST[state]\" />
</td><td>
<input type=\"text\" size=\"5\" name=\"zip\" value=\"$_POST[zip]\" />
</td></tr></table>
<br />
<input type=\"submit\" name=\"submit2\" class=\"textfield\" value=\"Submit Address\" />
</form>
";




} else {

$result = mysql_query("SELECT * FROM plants WHERE id='$id'") or DIE(mysql_error());
while($r=mysql_fetch_array($result))
{

$id=$r["id"];
$plantloc=$r["plantloc"];
$city=$r["city"];
$state=$r["state"];
$zip=$r["zip"];
$street=$r["street"];

}

$address = "$street<br />$city, $state - $zip";

if (isset($default)){
$_SESSION['tempaddress'] = 0;
header("Location: index.php?page=checkout");
}

if ($_SESSION['tempaddress'] == 1){
$displayaddress = "
$_SESSION[street]<br />
$_SESSION[city], $_SESSION[state] $_SESSION[zip]<br />
";
}



if (isset ($_POST['submit']))
{

$problem = FALSE;

      if (!isset($_POST['checktos'])) {
$problem = TRUE;
$error .= 'You must agree to the Terms of Service to complete your order. <br />';
      }

      if (empty ($_POST['ponumber'])) {
$problem = TRUE;
$error .= 'A PO number is required for checkout. <br />';
      }

      if (empty ($_POST['firstname'])) {
$problem = TRUE;
$error .= 'Your first name is required for checkout. <br />';
      }

      if (empty ($_POST['lastname'])) {
$problem = TRUE;
$error .= 'Your last name is required for checkout. <br />';
      }

      if (empty ($_POST['phonenumber1'])) {
$problem = TRUE;
$error .= 'Phone Number is a required field and all three blanks must be completed. <br />';
      } elseif (empty ($_POST['phonenumber2'])) {
$problem = TRUE;
$error .= 'Phone Number is a required field and all three blanks must be completed. <br />';
      } elseif (empty ($_POST['phonenumber3'])) {
$problem = TRUE;
$error .= 'Phone Number is a required field and all three blanks must be completed. <br />';
      }

if (!$problem) {

$ponumber = $_POST['ponumber'];
$shipping = $_POST['shipping'];
$notes = $_POST['notes'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$name = "$firstname $lastname";
$phonenumber1 = $_POST['phonenumber1'];
$phonenumber2 = $_POST['phonenumber2'];
$phonenumber3 = $_POST['phonenumber3'];
$telephone = "$_POST[phonenumber1]-$_POST[phonenumber2]-$_POST[phonenumber3]";

if (isset($default)){
$_SESSION['tempaddress'] = 0;
}

if ($_SESSION['tempaddress'] == 1){
$displayaddress = "
$_SESSION[street]<br />
$_SESSION[city], $_SESSION[state] $_SESSION[zip]<br />
";
}

$color1 = "#dddddd";
    $color2 = "#c0c0c0";
    $row_count = 0;

$parts .= "
<table width=732 cellpadding=3><tr bgcolor=#8d8d8d cellspacing=6><td width=10 align=center><b>LOC</b></td><td width=100><b>Part Number</b></td><td width=330><b>Description</b></td><td><b>Price</b></td><td><b>QTY</b></td></tr>";

$result2 = mysql_query("SELECT * FROM parts ORDER BY id ASC") or DIE(mysql_error());
while($r2=mysql_fetch_array($result2))
{
$pid=$r2["id"];
$loc=$r2["LOC"];
$pn=$r2["PN"];
$desc=$r2["DESC"];
$price=$r2["PRICE"];
$sub = $r2["SUB"];

$row_color = ($row_count % 2) ? $color1 : $color2;


$quan = ($_SESSION['cart'][$pid] < 1) ? "0" : $_SESSION['cart'][$pid];

if ($quan > 0){

if ($sub == 0){
$parts .= "<tr cellspacing=6><td align=center bgcolor=\"$row_color\">$loc</td><td bgcolor=\"$row_color\" width=\"100\">$pn</td><td bgcolor=\"$row_color\" width=\"330\">$desc</td><td bgcolor=\"$row_color\">$price</td><td bgcolor=\"$row_color\">$quan</td></tr>";
$row_count++;
} else {
$parts .= "<tr cellspacing=6><td align=center bgcolor=\"$row_color\">$loc-$sub</td><td bgcolor=\"$row_color\" width=\"100\">$pn</td><td bgcolor=\"$row_color\" width=\"330\">$desc</td><td bgcolor=\"$row_color\">$price</td><td bgcolor=\"$row_color\">$quan</td></tr>";
$row_count++;
}
$total = $total + ($price * $quan);

}



}
include "Rate.php5";

$parts .= "<tr cellspacing=6><td align=center></td><td></td><td align=right><B>TOTAL</B></td><td bgcolor=yellow>$total</td><td></td></tr></table>";


$datetime = date('m/d/Y - g:i A');


$result = MYSQL_QUERY("INSERT INTO orders (po,plantloc,address,telephone,name,notes,shipping,parts,datetime)".
"VALUES ('$ponumber', '$plantloc', '$address2', '$telephone', '$name', '$notes', '$shipping', '$parts', '$datetime')") or die (mysql_error());

$emailbody = "<font style=verdana>
<table width=732 cellpadding=3><tr bgcolor=#f3f3f3 cellspacing=6><td>
<u>$plantloc</u></td><td>$name - $telephone</td><tr><td>
$address2</td><td>

<table><tr><td align=right>
<b>PO #:</b>
</td><td>
$ponumber
</td></tr><tr><td align=right>
<b>Shipping:</b>
</td><td>
$shipping
</td></tr><tr><td align=right>
<b>Date:</b>
</td><td>
$datetime
</td></tr></table>

</td></tr></table>
<br />
   <u>Special Notes</u>
<table width=732 cellpadding=3 bgcolor=f3f3f3>
<tr><td>$notes</td></tr>
</table>
<br />
$parts<br /><br />
</font>
";


$to  = 'tcantwell@berryequipment.net' . ', '; // note the comma

// subject
$subject = 'Purchase Orders';

// message
$message = "
<html>
<head>
</head>
<body>
$emailbody
</body>
</html>
";

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Candace Painter <cpainter@berryequipment.net>' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);


                      header("Location: index.php?page=thankyou");
					exit;




} }









$content .= "
<h1>Checkout</h1>
";

$color1 = "#dddddd";
    $color2 = "#c0c0c0";
    $row_count = 0;

$content .= "
<table width=732 cellpadding=3><tr bgcolor=#8d8d8d cellspacing=6><td width=10 align=center>LOC</td><td width=100>Part Number</td><td width=330>Description</td><td>Price</td><td>QTY</td></tr>";

$result2 = mysql_query("SELECT * FROM parts ORDER BY LOC ASC") or DIE(mysql_error());
while($r2=mysql_fetch_array($result2))
{
$pid=$r2["id"];
$loc=$r2["LOC"];
$pn=$r2["PN"];
$desc=$r2["DESC"];
$price=$r2["PRICE"];
$sub=$r["SUB"];

$row_color = ($row_count % 2) ? $color1 : $color2;


$quan = ($_SESSION['cart'][$pid] < 1) ? "0" : $_SESSION['cart'][$pid];

if ($quan > 0){
if ($sub == 0) {
$content .= "<tr cellspacing=6><td align=center bgcolor=\"$row_color\">$loc</td><td bgcolor=\"$row_color\" width=\"100\">$pn</td><td bgcolor=\"$row_color\" width=\"330\">$desc</td><td bgcolor=\"$row_color\">$price</td><td bgcolor=\"$row_color\">$quan</td></tr>";
$row_count++;
} else {
$content .= "<tr cellspacing=6><td align=center bgcolor=\"$row_color\">$loc-$sub</td><td bgcolor=\"$row_color\" width=\"100\">$pn</td><td bgcolor=\"$row_color\" width=\"330\">$desc</td><td bgcolor=\"$row_color\">$price</td><td bgcolor=\"$row_color\">$quan</td></tr>";
$row_count++;
}
$total = $total + ($price * $quan);

}


}
$content .= "<tr cellspacing=6><td align=center></td><td></td><td></td><td bgcolor=yellow><b>$total</b></td><td></td></tr>";

if ($_SESSION['tempaddress'] == 1) {
$address2 = $displayaddress;
} else {
$address2 = $address;
}

$content .= "
<form action=\"index.php?page=checkout\" method=\"post\" name=\"checkout\">
<table>
<tr><td width=250 valign=top>
Shipping Address:<br />
$_SESSION[tempaddress]
<p>$address2</p><br />
<a href=index.php?page=checkout&alternate=change>Ship to alternate location</a>
<br />
<a href=index.php?page=checkout&default=true>Reset default address</a>
</td><td valign=top width=450>
First Name:<br />
<input type=\"text\" size=\"20\" name=\"firstname\" value=\"$_POST[firstname]\" /><br /><br />
Last Name:<br />
<input type=\"text\" size=\"20\" name=\"lastname\" value=\"$_POST[lastname]\" /><br /><br />
Shipping Method:<br />
<select name=shipping>
<option value=\"Ground\">Ground</option>\n
<option value=\"Expedite\">Expedite</option>\n
<option value=\"Expedite A.M.\">Expedite A.M.</option>\n
<option value=\"Expedite Saturday\">Expedite Saturday</option>\n
<option value=\"2 Day\">2nd Day</option>\n
<option value=\"3 Day\">3rd Day</option>\n
</select>
<br /><br />
PO Number:<br />
<input type=\"text\" size=\"20\" name=\"ponumber\" value=\"$_POST[ponumber]\" /><br /><br />
Contact Telephone #:<br />
<input type=\"text\" size=\"3\" onKeyup=\"autotab(this, document.checkout.phonenumber2)\" maxlength=3 name=\"phonenumber1\" value=\"$_POST[phonenumber1]\" />
<input type=\"text\" size=\"3\"  onKeyup=\"autotab(this, document.checkout.phonenumber3)\" maxlength=3 name=\"phonenumber2\" value=\"$_POST[phonenumber2]\" />
<input type=\"text\" size=\"3\" maxlength=4 name=\"phonenumber3\" value=\"$_POST[phonenumber3]\" />
<br /><br />
Special Notes:<br />
<textarea cols=\"30\" rows=\"3\" name=\"notes\" value=\"$_POST[notes]\"></textarea>

</td></tr></table>

<p align=left><input type=\"checkbox\" name=\"checktos\" value=\"tos\"> I agree to the <a href=#>Terms of Service</a>.</p>
<p align=right><input type=\"submit\" name=\"submit\" class=\"textfield\" value=\"Checkout\" /></p>
</form>
";

}




?>

 

 

It has the checkout page and the address change combined. The link to change your address is on the checkout page, if it sets to that it shows the address change form and then when you submit it, it'll run the script to set the sessions and whatnot and then go back to the main checkout page.

Link to comment
Share on other sites

if (empty ($_POST['street'])) {
$problem = TRUE;
$error .= 'Street is a required field. <br />';
      }

      elseif (empty ($_POST['city'])) {
$problem = TRUE;
$error .= 'City is a required field. <br />';
      }

      elseif (empty ($_POST['state'])) {
$problem = TRUE;
$error .= 'State is a required field. <br />';
      }

      elseif (empty ($_POST['zip'])) {
$problem = TRUE;
$error .= 'Zip is a required field. <br />';
      }

 

Your supose to use elseif, your script is also too large to look through.

Link to comment
Share on other sites

See the problem with all the help suggestions is, each thing you guys are saying to change, isn't the problem. Those are simply error message call outs. I'm not using elseif because that will stop whenever it hits a problem, and I want to display multiple problems. This works perfectly fine. The reason I posted the entire script is because a lot of times, I'll post the part that is important and people will tell me to post the entire code. Let me try and pinpoint the problematic areas though:

 

if ($_GET['alternate'] == "change"){
$result = mysql_query("SELECT * FROM plants WHERE id='$id'") or DIE(mysql_error());

while($r=mysql_fetch_array($result))
{

$id=$r["id"];
$plantloc=$r["plantloc"];
$address=$r["address"];
$ph=$r["PH"];


}




if (isset ($_POST['submit2']))
{

$problem = FALSE;


      if (empty ($_POST['street'])) {
$problem = TRUE;
$error .= 'Street is a required field. <br />';
      }

      if (empty ($_POST['city'])) {
$problem = TRUE;
$error .= 'City is a required field. <br />';
      }

      if (empty ($_POST['state'])) {
$problem = TRUE;
$error .= 'State is a required field. <br />';
      }

      if (empty ($_POST['zip'])) {
$problem = TRUE;
$error .= 'Zip is a required field. <br />';
      }





if (!$problem) {

$_SESSION['city'] = ucwords($_POST['city']);
$_SESSION['state'] = strtoupper($_POST['state']);

$_SESSION['zip'] = $_POST['zip'];
$_SESSION['street'] = $_POST['street'];
$_SESSION['tempaddress'] = 1;

                      header("Location: index.php?page=checkout");
					exit;

}

}




$content .= "
<p><u><a href=\"index.php?page=accounthome\">$plantloc</a></u> - Alternate Address </p>

<form action=\"index.php?page=checkout&alternate=change\" method=\"post\">
Street:<br />
<input type=\"text\" size=\"20\" name=\"street\" value=\"$_POST[street]\" /><br /><br />
<table><tr><td>
City:
</td><td>
State:
</td><td>
Zip:
</td></tr>
<tr><td>
<input type=\"text\" size=\"10\" name=\"city\" value=\"$_POST[city]\" />
</td><td>
<input type=\"text\" size=\"2\" name=\"state\" value=\"$_POST[state]\" />
</td><td>
<input type=\"text\" size=\"5\" name=\"zip\" value=\"$_POST[zip]\" />
</td></tr></table>
<br />
<input type=\"submit\" name=\"submit2\" class=\"textfield\" value=\"Submit Address\" />
</form>
";




}

 

With the above code, if the variable is set in the url (which we are assuming it is) then the change address form will be presented for the user. Once submitted, they will still be at the page with that variable set and it will hit the if (isset(submit2)) part of the script and if there are no errors, it will set the sessions and throw them back to the normal checkout page (without the variable being set in the url).

 

On the normal checkout page, we try to check if they set a new address, if they did we display it and if not we use the old address:

 

if ($_SESSION['tempaddress'] == 1){
$displayaddress = "
$_SESSION[street]<br />
$_SESSION[city], $_SESSION[state] $_SESSION[zip]<br />
";
}


if ($_SESSION['tempaddress'] == 1) {
$address2 = $displayaddress;
} else {
$address2 = $address;
}

 

 

Maybe with pinpointing the exact portions of the code that this problem is persisting to, it'll be easier to read through and figure out the problem? Thanks!

Link to comment
Share on other sites

Time for edits passed by time I typed this up, I am sorry for double posting but:

 

 

 

ps: keep in mind, I am echoing the results of session [tempaddress] and it is displaying a 1 when the new address has been submitted, and a 0 when it is not submitted, though when it is displaying the 1.. it isn't showing the correct (new) address.

 

Here is what the two differences in format look like:

 

temp = 0

301 East Cherry Street

Clarksville, AR - 72830

 

 

temp = 1

301 East Cherry Street

Clarksville, AR 72830

 

 

Notice the - in the original, the second is formatted differently (not on purpose, but it does show that it is setting it by the rules we told it to go by, its just using the variables from the database...) I'm also entering in random wordings/numbers for this address, so it shouldn't be anywhere near the same.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.