Jump to content

Problem with Shopping cart


jeps

Recommended Posts

I am currently learning php and I am using Practical PHP and MySQL® Building Eight Dynamic Web Applications by Jono Bacon

 

I know this is not the best book to learn from but it is what I was given.

 

My current problem is that when logged in and have items in the shopping cart, I go to the check out and can not go any further.

 

I don't get any errors it just does nothing but show an address form that just clears if you add an address

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/232809-problem-with-shopping-cart/
Share on other sites

I had a quick scan try these

 

on line 130 add

enctype='multipart/form-data'

into the form line

why on lines 22 -> 35 have you got ``

if($_POST[‘submit’])
{
	if($_SESSION[‘SESS_LOGGEDIN’])
	{
		if($_POST[‘addselecBox’] == 2)
		{
			if(empty($_POST[‘forenameBox’]) ||
				empty($_POST[‘surnameBox’]) ||
				empty($_POST[‘add1Box’]) ||
				empty($_POST[‘add2Box’]) ||
				empty($_POST[‘add3Box’]) ||
				empty($_POST[‘postcodeBox’]) ||
				empty($_POST[‘phoneBox’]) ||
				empty($_POST[‘emailBox’]))

you could try

if($_POST['submit'])
{
	if($_SESSION['SESS_LOGGEDIN'])
	{
		if($_POST['addselecBox'] == 2)
		{
			if(empty($_POST['forenameBox']) ||
				empty($_POST['surnameBox']) ||
				empty($_POST['add1Box']) ||
				empty($_POST['add2Box']) ||
				empty($_POST['add3Box']) ||
				empty($_POST['postcodeBox']) ||
				empty($_POST['phoneBox']) ||
				empty($_POST['emailBox']))

 

Well i got bored heres somthing that should b ok, i didnt test though

<?php
session_start();
require("db.php");
$check = array('forenameBox','surnameBox','add1Box','add2Box','add3Box','postcodeBox','phoneBox','emailBox');
function isempty($array)
{
  global $check;
  foreach($array as $key => $val)
  {
	if(empty($val)&&in_array($key,$check)){return true;}  
  }
  return false;
}
function tidy($var,$b4=NULL,$after=NULL)
{
  if(is_array($var))
  {
	foreach($array as $key => $val)
    {
	  return $b4.strip_tags(addslashes($val)).$after;
	}
  }
  else
  {
	return $b4.strip_tags(addslashes($var)).$after;
  }
}
$statussql = "SELECT status FROM orders WHERE id = " . $_SESSION['SESS_ORDERNUM'];
$statusres = mysql_query($statussql);
$statusrow = mysql_fetch_assoc($statusres);
$status = $statusrow['status'];

	if($status == 1) {
		header('Location: ' . $config_basedir . 'checkout-pay.php');
	}

	if($status >= 2) {
		header('Location: ' . $config_basedir);
	}

	if($status >= 2) {
		header('Location: ' . $config_basedir);
	}

if($_POST[‘submit’])
{
	if($_SESSION[‘SESS_LOGGEDIN’])
	{
		if($_POST[‘addselecBox’] == 2)
		{

			if(isempty($_POST))
			{
				header('Location: ' . $basedir . 'checkout-address.php?error=1');
				exit;
			}
			$addsql = "INSERT INTO
delivery_addresses(forename, surname, add1,
add2, add3, postcode, phone, email)
				VALUES('" 	. tidy($_POST['forenameBox']) 
							. "', '" . tidy($_POST['surnameBox']) 
							. "', '" . tidy($_POST['add1Box']) 
							. "', '" . tidy($_POST['add2Box']) 
							. "', '" . tidy($_POST['add3Box']) 
							. "', '" . tidy($_POST['postcodeBox']) 
							. "', '" . tidy($_POST['phoneBox']) 
							. "', '" . tidy($_POST['emailBox']) . "')";

					mysql_query($addsql);

					$setaddsql = "UPDATE orders SET
	delivery_add_id = " . mysql_insert_id() . ",
	status = 1 WHERE id = "
	 . $_SESSION['SESS_ORDERNUM'];
					mysql_query($setaddsql);

					header("Location: "
	  . $config_basedir . "checkout-pay.php");
		}

		else
		{
			$custsql = "UPDATE orders SET
	delivery_add_id = 0, status = 1 WHERE id = " .
$_SESSION['SESS_ORDERNUM'];
		mysql_query($custsql);
		header("Location: " . $config_basedir . "checkout-pay.php");
	}
}

else
{
	if(isempty($_POST))
	{
		header("Location: " . "checkout-address.php?error=1");
		exit;
	}

	$addsql = "INSERT INTO
delivery_addresses(forename, surname, add1,
add2, add3, postcode, phone, email)
	VALUES('"
	 . $_POST['forenameBox'] . "', '"
	 . $_POST['surnameBox'] . "', '"
	 . $_POST['add1Box'] . "', '"
	 . $_POST['add2Box'] . "', '"
	 . $_POST['add3Box'] . "', '"
	 . $_POST['postcodeBox'] . "', '"
	 . $_POST['phoneBox'] . "', '"
	 . $_POST['emailBox'] . "')";

	mysql_query($addsql);

$setaddsql = "UPDATE orders
SET delivery_add_id = " . mysql_insert_id()
. ", status = 1 WHERE session = '"
. session_id() . "'";
	mysql_query($setaddsql);

	header("Location: " . $config_basedir . "checkout-pay.php");
	}
}

else
{

require("header.php");
echo "<h1>Add a delivery address</h1>";

if(isset($_GET['error']) == TRUE) {
	echo "<strong>Please fill in the missing
information from the form</strong>";
}

echo "<form action='" . $SCRIPT_NAME . "' method='POST'>";

if($_SESSION['SESS_LOGGEDIN'])
{
?><form enctype='multipart/form-data'
<input type="radio" name="addselecBox"
value="1" checked>Use the address from my
account</input><br>
<input type="radio" name="addselecBox"
value="2">Use the address below:</input>

<?php
}

?>
	<table>
	<tr>
		<td>Forename</td>
		<td><input type="text" name="forenameBox"></td>
	</tr>
	<tr>
		<td>Surname</td>
		<td><input type="text" name="surnameBox"></td>
	</tr>
	<tr>
		<td>House Number, Street</td>
		<td><input type="text" name="add1Box"></td>
	</tr>
	<tr>
		<td>Town/City</td>
		<td><input type="text" name="add2Box"></td>
	</tr>
	<tr>
		<td>County</td>
		<td><input type="text" name="add3Box"></td>
	</tr>
	<tr>
		<td>Postcode</td>
		<td><input type="text" name="postcodeBox"></td>
	</tr>
	<tr>
		<td>Phone</td>
		<td><input type="text" name="phoneBox"></td>
	</tr>
	<tr>
		<td>Email</td>
		<td><input type="text" name="emailBox"></td>
	</tr>
	<tr>
		<td></td>
		<td><input type="submit" name="submit"
value="Add Address (press only once)"></td>
	</tr>
	</table>
</form>	

<?php
}
require("footer.php");
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.