Insert Order() Problem

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
mmc01ms
Forum Commoner
Posts: 97
Joined: Wed Dec 01, 2004 3:33 am
Location: Nottingham, UK

Insert Order() Problem

Post by mmc01ms »

Hi guys im trying to insert an order into my database the problem is that i have a set of values that have been posted from a form these being the address, name of the customer etc. Now after the user clicks the purchase button they are taken to the purchase page which in the meantime inserts the order into the database. The query is fine and i know it is inserting the right values. The problem lays with the $order_details inside the insert order. It is not extracting the values for the address that were posted. Im not using globals and don't wish too. Can anyone see what the problem is? code is

Code: Select all

<?php
	&#125;
		
		function insert_order($order_details)&#123;
			
			
			extract($order_details);
			
			$delivery = $_SESSION&#1111;'shipping'];
			$name = $ship_name;
			$title = $ship_title;
			$surname = $ship_surname;
			$address1 = $ship_address1;
			$town = $ship_town;
			$city = $ship_city;
			$county = $ship_county;
			$postcode = $ship_postcode;
			$total = ($_SESSION&#1111;'total_price']+$_SESSION&#1111;'shipping']);
			$customer_id = $_SESSION&#1111;'customer_id'];
			
			$link_id = db_connect();
			$date = date('Y-m-d');
			$query = "insert into orders (order_id, customer_id, order_status, date_order_placed, delivery_charge, ship_name, ship_surname,
 						ship_title, ship_address1, ship_address2, ship_city, ship_county, ship_postcode, order_note, total)
						values(NULL, '$customer_id', 'Unprocessed orders', '$date', '$delivery','$name','$surname','$title','$address1',
 						'$town','$city','$county','$postcode', NULL,'$total')";
			$result = mysql_query($query);
			if (!$result)
				return false;
		&#125;
				
				
	?>

Code: Select all

<?php
	
	session_start(); //must start a session for cart
	
	//$qty = $_GET&#1111;'qty'];
	
	
		//checkout.php written by Manpreet Sandhu 26/01/2005
	require('page.inc'); //page class	
	require_once('shopping_basket_fns.php');
	
	$purchase = new Page();//create new page object
	
	$purchase -> Display();//use function display from page class
	
	display_main_menu(); //display side bar menu
	
	
	//posted values from checkout_form().
	
	//$ship_delivery = $_SESSION&#1111;'shipping'];
	$ship_name = $_POST&#1111;'ship_name'];
	$ship_title = $_POST&#1111;'ship_title'];
	$ship_surname = $_POST&#1111;'ship_surname'];
	$ship_address1 = $_POST&#1111;'ship_address_1'];
	$ship_town = $_POST&#1111;'ship_town'];
	$ship_city = $_POST&#1111;'ship_city'];
	$ship_county = $_POST&#1111;'ship_county'];
	$ship_postcode = $_POST&#1111;'ship_postcode'];
	//$total = ($_SESSION&#1111;'total_price']+$_SESSION&#1111;'shipping']);
	//$customer_id = $_SESSION&#1111;'customer_id'];
	
	//if all values have been entered we can insert the order into the database
	
	if(insert_order($_POST)!= false)
	&#123;
		insert_order();
		display_cart($_SESSION&#1111;'cart'], false, 0);//display contents of cart
		display_shipping(calculate_shipping_cost($items));//display total shipping cost
		display_card_form();//display credit card form
	&#125;else
	
	print 'Could not store data';
	
	
	
	
	
	do_html_footer();
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what's output?
mmc01ms
Forum Commoner
Posts: 97
Joined: Wed Dec 01, 2004 3:33 am
Location: Nottingham, UK

Post by mmc01ms »

bypasses the ifs and goes straigh to the last line of the statement which is

Could not store data


so it's not picking up the $_POST's
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

make sure your insert query is valid.
mmc01ms
Forum Commoner
Posts: 97
Joined: Wed Dec 01, 2004 3:33 am
Location: Nottingham, UK

Post by mmc01ms »

this time it is valid after last time it was the first thing i checked. my table for orders is as followed:

Code: Select all

create table orders
(order_id int unsigned not null auto_increment primary key,
customer_id int(6) not null,
order_status char(10) not null default'',
date_order_placed date not null default'0000-00-00',
delivery_charge int unsigned not null,
ship_name varchar(20) not null default'',
ship_surname varchar(20) not null default'',
ship_title varchar(4) not null default'',
ship_address1 varchar(25) not null default'',
ship_address2 varchar(25) default'',
ship_city varchar(15) not null default'',
ship_county varchar(15) default'',
ship_postcode char(8) not null default'',
order_note varchar(50) default'',
total  float(4,2));

any other ideas?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

make sure you return non-false from the function when it works.
mmc01ms
Forum Commoner
Posts: 97
Joined: Wed Dec 01, 2004 3:33 am
Location: Nottingham, UK

Post by mmc01ms »

sorry i didn't get what you meant?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

currently you return nothing when the function succeeds, this may be considered false by your code.
mmc01ms
Forum Commoner
Posts: 97
Joined: Wed Dec 01, 2004 3:33 am
Location: Nottingham, UK

Post by mmc01ms »

doing (!=true) brings:

Code: Select all

Warning: Missing argument 1 for insert_order() in /home/sites/manpreetsandhu.com/public_html/shopping_basket_fns.php on line 344

Warning: extract(): First argument should be an array in /home/sites/manpreetsandhu.com/public_html/shopping_basket_fns.php on line 347
doing (==true) does the same as (!=false)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you changed the wrong part of the code, it would appear.
Post Reply