Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

logical flow problem

Status
Not open for further replies.

boab

Programmer
May 30, 2001
75
GB
Hi guys my script is working without error or warning messages but the site does not respond can any1 see the problem in the functions below?

Script 1
<?

include ('product_sc_fns.php');
// The shopping cart needs sessions, so start one
session_start();

do_html_header(&quot;Checkout&quot;);

// if filled out
if($cart&&$name&&$first_add&&$city&&$zip&&$country)
{
// able to insert into database
if( insert_order($HTTP_POST_VARS)!=false )
{
$orderId=insert_order($HTTP_POST_VARS);
//display cart, not allowing changes and without pictures
display_cart($cart, false, 0);

display_shipping(calculate_shipping_cost());

//get credit card details
display_card_form($name,$orderId);

display_button(&quot;show_cart.php&quot;, &quot;continue-shopping&quot;, &quot;Continue Shopping&quot;);
}
else
{
echo &quot;Could not store data, please try again.&quot;;
display_button(&quot;checkout.php&quot;, &quot;back&quot;, &quot;Back&quot;);
}
}
else
{
echo &quot;You did not fill in all the fields, please try again.<hr>&quot;;
display_button(&quot;checkout.php&quot;, &quot;back&quot;, &quot;Back&quot;);
}

do_html_footer();
?>

Script 2

<?
include ('product_sc_fns.php');
// The shopping cart needs sessions, so start one
session_start();

do_html_header(&quot;Checkout&quot;);

if($cart&&$card_type&&$card_number&&$card_month&&$card_year&&$card_name )
{
//display cart, not allowing changes and without pictures
display_cart($cart, false, 0);

display_shipping(calculate_shipping_cost());

if(process_card($HTTP_POST_VARS))
{

$toaddress=&quot;info@stewarthighland.com&quot;;
$subject=&quot;You have a new order&quot;;
$fromaddress=&quot;RJSneddon@blueyonder.co.uk&quot;;
$content=&quot;You have a new order click the link to view //empty shopping cart
session_destroy();
echo &quot;Thankyou for shopping with us. Your order has been placed.&quot;;
display_button(&quot;index.php&quot;, &quot;continue-shopping&quot;, &quot;Continue Shopping&quot;);
}
else
{
echo &quot;Could not process your card, please contact the card issuer or try again.&quot;;
display_button(&quot;purchase.php&quot;, &quot;back&quot;, &quot;Back&quot;);
}
}
else
{
echo &quot;You did not fill in all the fields, please try again.<hr>&quot;;
display_button(&quot;purchase.php&quot;, &quot;back&quot;, &quot;Back&quot;);
}

do_html_footer();
?>


Script 3

function process_card($card_details)
{
$end=$card_month.&quot;/&quot;.$card_year;
$conn=db_connect();
$query=&quot;select threed from ccdet where ccno='$card_number'&quot;;
$result=mysql_query($query);
if($result >0)
{
return false;
}
else
{
$query=&quot;insert into ccdet values('','$card_number','$end','','Threed','$card_type','card_name')&quot;;
return true;
}

}

function insert_order($order_details)
{
global $total_price;
global $cart;
//extract order_details out as variables
extract($order_details);


//set shipping address same as address
if(!$ship_name&&!$ship_1st_add&&!$ship_2nd_add&&!$ship_city&&!$ship_state&&!$ship_zip&&!$ship_country)
{
$ship_name = $name;
$ship_1st_add = $first_add;
$ship_2nd_add = $second_add;
$ship_city = $city;
$ship_state = $state;
$ship_zip = $zip;
$ship_country = $country;
}



//insert customer address
$query = &quot;select customerid from contact where name = '$name' and 1st_add = '$first_add' and 2nd_add = '$second_add' and town = '$city' and state = '$state' and zip = '$zip' and country = '$country'&quot;;
$result = @mysql_query($query);

if(mysql_num_rows($result)>0)
{
$customerid = mysql_result($result, 0, &quot;customerid&quot;);
}
else
{
$query = &quot;insert into contact values
('', '$name', '$first_add','$second_add','$city','$state','$zip','$tel','$fax','$country','$email')&quot;;
$result = mysql_query($query);
if (!$result)
return false;
}

$date = date(&quot;Y-m-d&quot;);
$query = &quot;insert into orders values
('','$customerid','$total_price','$date','PARTIAL','$ship_name',
'$ship_1st_add','$ship_2nd_add','$ship_city','$ship_state','$ship_zip',
'$ship_country')&quot;;
$result = mysql_query($query);
if (!$result)
return false;

$query = &quot;select orderid from orders where
customerid = $customerid and
amount > $total_price-.001 and
amount < $total_price+.001 and
date = '$date' and
order_status = 'PARTIAL' and
ship_name = '$ship_name' and
ship_1st_add = '$ship_1st_add' and
ship_2nd_add = '$ship_2nd_add' and
ship_city = '$ship_city' and
ship_state = '$ship_state' and
ship_zip = '$ship_zip' and
ship_country = '$ship_country'&quot;;
$result = mysql_query($query);
if(mysql_num_rows($result)>0)
$orderid = mysql_result($result, 0, &quot;orderid&quot;);
else
return false;


// insert each product
foreach($cart as $productId => $quantity)
{
$detail = get_product_details($productId);
$query = &quot;delete from order_items where
orderid = '$orderid' and productId = '$productId'&quot;;
$result = mysql_query($query);
$query = &quot;insert into order_items values
('$orderid', '$productId', &quot;.$detail[&quot;price&quot;].&quot;, $quantity)&quot;;
$result = mysql_query($query);
if(!$result)
return false;
}

return $orderid;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top