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
mmc01ms
Forum Commoner
Posts: 97 Joined: Wed Dec 01, 2004 3:33 am
Location: Nottingham, UK
Post
by mmc01ms » Wed Jan 26, 2005 2:16 pm
Im trying to get the value of the shipping cost returned to a checkout form. I have functions that caculate shipping costs and return values the only problem is that i get the following error
Code: Select all
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sites/manpreetsandhu.com/public_html/shopping_basket_fns.php on line 206
Not sure why must be doing something wrong with the sql??Any one help?
code is below:
Code: Select all
<?php
session_start(); //must start a session for cart
$qty = $_GETї'qty'];
//checkout.php written by Manpreet Sandhu 26/01/2005
require('page.inc'); //page class
require_once('shopping_basket_fns.php');
$checkout = new Page();//create new page object
$checkout -> Display();//use function display from page class
display_main_menu(); //display side bar menu
$link_id = db_Connect();//connect the database
//query the database to retrieve all information out of the database regarding the current customer using the
//registered session variable which is their customer id.
$query = mysql_query("SELECT * FROM customers WHERE customer_id='".$_SESSIONї'customer_id']."'",$link_id);
$c = mysql_fetch_array($query);//fetch the results of the query and for them in an array and assign the value $c
//to pass through to the display_checkout_form function.
print '<table width="600">';
print '<center><th align="center" colspan="6">';
print "Checkout";
print '</th></center>';
print '<tr>';
print '<td>';
print "ї<a href='show_cart.php'>Back</a>]";
print "ї<a href='vinyls.php'>Search for more vinyls</a>]";
print '</td>';
print '</tr>';
print '<table>';
print '<p></p>';
if($_SESSIONї'cart']&&array_count_values($_SESSIONї'cart']))
{//if session values exist then display cart with the items and the checkout form else echo message
display_cart($_SESSIONї'cart'], false, 0);
display_shipping(calculate_shipping_cost($qty));
display_checkout_form($c);
}
else
print 'There are no items in your cart';
do_html_footer();
?>
Code: Select all
<?php
//shopping_basket_fns.php written by Manpreet Sandhu 12/01/2005
require_once('news_fns.php');
function display_cart($cart, $change = true, $images = 1)
{
//display what is in the shopping basket
$cart = $_SESSIONї'cart'];
echo '<table border="0" width="100%" cellspacing="0">
<form action="show_cart.php" method="post">
<tr><th colspan="'. (1+$images) .'" bgcolor="#7b9815">Item</th>
<th bgcolor="#7b9815">Price</th><th bgcolor="#7b9815">Qty</th>
<th bgcolor="#7b9815">Total</th></tr>';
//display each item as a table row
foreach ($cart as $catno => $qty)
{
$vinyl = get_vinyl_details($catno);
print '<tr>';
if($images == true)
{
print '<td align="left">';
if(file_exists("images/$catno.jpg"))
{
$size = GetImageSize('images/'. $catno. '.jpg');
if($sizeї0] > 0 && $sizeї1] > 0)
{
print '<img src="images/'. $catno. '.jpg" ';
print 'width='. $sizeї0]/3 .'height = '.$sizeї1]/3 . '>';
}
}
else
print ' ';
print '</td>';
}
print '<td align="left">';
print '<font color="#44802c" size="3" face="Arial, Helvetica, sans-serif"><a href="show_vinyls.php?cat_no='.$catno.'">'.$vinylї'title'].'</a> - '.$vinylї'artist_id'].'</font>';
print '</td><td align="center"><font color="#44802c" size="3" face="Arial, Helvetica, sans-serif">£'.number_format($vinylї'price'], 2).'</font>';
print '</td><td align="center">';
//allowing change of qty
if($change == true)//if change is true then show input box for qty
echo'<input type="text" name="'.$vinylї'cat_no'].'" value="'.$qty.'" size="1">';
else
echo $qty;//else just show qty and total price
print '</td><td align="center"><font color="#44802c" size="3" face="Arial, Helvetica, sans-serif">£'.number_format($vinylї'price']*$qty, 2).'</font></td></tr>';
}
//display of total row
echo '<tr>
<th colspan="'. (2+$images) .'" bgcolor="#7b9815"> </td>
<th align="center" bgcolor="#7b9815">'.$_SESSIONї'items'].'</th>
<th align="center" bgcolor="#7b9815">£'.number_format($_SESSIONї'total_price'], 2).'</th>
</tr>';
//offer save feature
if($change == true)
{
echo '<tr>
<td colspan="'. (2+$images) .'" </td>
<td align="center">
<input type="hidden" name="save" value="true">
<input type="hidden" name="cat_no" value="$catno">
<input type="hidden" name="qty" value="$qty">
<input type="submit" value="Update Changes" alt="Update Changes">
</td>
<td></td>
</tr>';
}
echo '</form></table>';
}
function calculate_price($cart)
{
// sum total price for all items in shopping cart
$price = 0.0;
if(is_array($cart))
{
$link_id = db_connect();
foreach($cart as $catno => $qty)
{
$query = "select price from vinyls where cat_no='".$catno."'";
$result = mysql_query($query, $link_id);
if ($result)
{
//$row = mysql_fetch_row($result);
$item_price = mysql_result($result, 0, 'price');
//$item_price = $rowї'price'];
$price +=$item_price*$qty;
}
}
}
return $price;
}
function calculate_items($cart)
{
//total items in the cart which goes through the cart and adds up the quantities of each item to get the total number og items
$items = 0;
if(is_array($cart))
{
foreach($cart as $catno => $qty)
{
$items += $qty;
}
}
return $items;
}
function get_customer_details($customer_id)
{
$link_id = db_connect();
$query = "select first_name, surname, postcode, address_line_one , address_line_two, city, county, initial from customers where customer_id = '$customer_id'";
$result = @mysql_query($query, $link_id) or die ("There was a problem with this query.");
if (!$result)
return false;
$num_cust = @mysql_num_rows($result);
if($num_cust == 0)
return false;
$result = db_result_to_array($result);
return $result;
}
function display_checkout_form($c){
//here we create a form where the users current address details in the database are brought up. If these are diffrent then the user
//can edit them to the required shipping address.
?>
<br />
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<form method="post" action="purchase.php" enctype="multipart/form-data">
<tr><th colspan="2" bgcolor="CCCCCC">Shipping Address (only change if delivering to another address)</th></tr>
<p></p>
<tr>
<td align="left">First Name: </td>
<td><input name="ship_name" type="text" size="40" maxlength="20" value="<?php echo $cї'first_name']; ?>"></td>
</tr>
<tr>
<td align="left">Last Name: </td>
<td><input name="ship_surname" type="text" size="40" maxlength="20" value="<?php print $cї'surname']; ?>"></td>
</tr>
<tr>
<td align="left">Title: </td>
<td><input name="ship_initial" type="text" size="40"maxlength="4" value="<?php echo $cї'initial']; ?>"></td>
</tr>
<tr>
<td align="left">Address Line One: </td>
<td><input name="ship_address_1" type="text" size="40" maxlength="25" value="<?php echo $cї'address_line_one']; ?>"></td>
</tr>
<tr>
<td align="left">Address Line Two: </td>
<td><input name="ship_address_2" type="text" size="40" maxlength="25" value="<?php echo $cї'address_line_two']; ?>"></td>
</tr>
<tr>
<td align="left">City: </td>
<td><input name="ship_city" type="text" size="40" maxlength="30" value="<?php echo $cї'city']; ?>"></td>
</tr>
<tr>
<td align="left">County: </td>
<td><input name="ship_county" type="text" size="40" maxlength="30" value="<?php echo $cї'county']; ?>"></td>
</tr>
<tr>
<td align="left">Postcode: </td>
<td><input name="ship_postcode" type="text" size="40" maxlength="8" value="<?php echo $cї'postcode']; ?>"></td>
</tr>
</form>
</table>
<?
}
function calculate_shipping_cost($qty)
{
//if the qty of items is greater then the qty number in the database then we have a max charge of £20.00 delivery
//if it is less then 15 then we check where the $qty of items is the same as qty in the table and retireive the correct
//postage cost for that item.
if($qty > 15)
{
$shipping_cost = 20.00;
}else
$link_id = db_connect();
//check the database to get the price of delivery depending on the number of items brought.
$query = 'select * from shipping_costs where qty ="'.$qty.'"';
$sc = mysql_fetch_array($query, $link_id);
{
$shipping_cost = $scї'delivery_charge'];
}
return $shipping_cost;
}
function display_shipping($shipping_cost)
{
//displays the shipping cost in then checkout and payment forms
?>
<br />
<table width="600">
<tr>
<th align="left">Shipping</th><th align="left"><?php echo number_format($shipping_cost, 2); ?></th>
<th><?php echo $shipping_cost; ?></th>
<th align="right">£<?php echo number_format($shipping_cost+$_SESSIONї'total_price'], 2); ?></th>
</tr>
</table><br />
<?php
}
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jan 26, 2005 2:21 pm
you didn't perform a query on or before that line to pass in a result.
mmc01ms
Forum Commoner
Posts: 97 Joined: Wed Dec 01, 2004 3:33 am
Location: Nottingham, UK
Post
by mmc01ms » Wed Jan 26, 2005 2:39 pm
i've passed in a result and it does indeed get rid of the error but still doesn't return a value that has been calculated for shipping. new code foe shopping basket functions
Code: Select all
<?php
//shopping_basket_fns.php written by Manpreet Sandhu 12/01/2005
require_once('news_fns.php');
function display_cart($cart, $change = true, $images = 1)
{
//display what is in the shopping basket
$cart = $_SESSIONї'cart'];
echo '<table border="0" width="100%" cellspacing="0">
<form action="show_cart.php" method="post">
<tr><th colspan="'. (1+$images) .'" bgcolor="#7b9815">Item</th>
<th bgcolor="#7b9815">Price</th><th bgcolor="#7b9815">Qty</th>
<th bgcolor="#7b9815">Total</th></tr>';
//display each item as a table row
foreach ($cart as $catno => $qty)
{
$vinyl = get_vinyl_details($catno);
print '<tr>';
if($images == true)
{
print '<td align="left">';
if(file_exists("images/$catno.jpg"))
{
$size = GetImageSize('images/'. $catno. '.jpg');
if($sizeї0] > 0 && $sizeї1] > 0)
{
print '<img src="images/'. $catno. '.jpg" ';
print 'width='. $sizeї0]/3 .'height = '.$sizeї1]/3 . '>';
}
}
else
print ' ';
print '</td>';
}
print '<td align="left">';
print '<font color="#44802c" size="3" face="Arial, Helvetica, sans-serif"><a href="show_vinyls.php?cat_no='.$catno.'">'.$vinylї'title'].'</a> - '.$vinylї'artist_id'].'</font>';
print '</td><td align="center"><font color="#44802c" size="3" face="Arial, Helvetica, sans-serif">£'.number_format($vinylї'price'], 2).'</font>';
print '</td><td align="center">';
//allowing change of qty
if($change == true)//if change is true then show input box for qty
echo'<input type="text" name="'.$vinylї'cat_no'].'" value="'.$qty.'" size="1">';
else
echo $qty;//else just show qty and total price
print '</td><td align="center"><font color="#44802c" size="3" face="Arial, Helvetica, sans-serif">£'.number_format($vinylї'price']*$qty, 2).'</font></td></tr>';
}
//display of total row
echo '<tr>
<th colspan="'. (2+$images) .'" bgcolor="#7b9815"> </td>
<th align="center" bgcolor="#7b9815">'.$_SESSIONї'items'].'</th>
<th align="center" bgcolor="#7b9815">£'.number_format($_SESSIONї'total_price'], 2).'</th>
</tr>';
//offer save feature
if($change == true)
{
echo '<tr>
<td colspan="'. (2+$images) .'" </td>
<td align="center">
<input type="hidden" name="save" value="true">
<input type="hidden" name="cat_no" value="$catno">
<input type="hidden" name="qty" value="$qty">
<input type="submit" value="Update Changes" alt="Update Changes">
</td>
<td></td>
</tr>';
}
echo '</form></table>';
}
function calculate_price($cart)
{
// sum total price for all items in shopping cart
$price = 0.0;
if(is_array($cart))
{
$link_id = db_connect();
foreach($cart as $catno => $qty)
{
$query = "select price from vinyls where cat_no='".$catno."'";
$result = mysql_query($query, $link_id);
if ($result)
{
//$row = mysql_fetch_row($result);
$item_price = mysql_result($result, 0, 'price');
//$item_price = $rowї'price'];
$price +=$item_price*$qty;
}
}
}
return $price;
}
function calculate_items($cart)
{
//total items in the cart which goes through the cart and adds up the quantities of each item to get the total number og items
$items = 0;
if(is_array($cart))
{
foreach($cart as $catno => $qty)
{
$items += $qty;
}
}
return $items;
}
function get_customer_details($customer_id)
{
$link_id = db_connect();
$query = "select first_name, surname, postcode, address_line_one , address_line_two, city, county, initial from customers where customer_id = '$customer_id'";
$result = @mysql_query($query, $link_id) or die ("There was a problem with this query.");
if (!$result)
return false;
$num_cust = @mysql_num_rows($result);
if($num_cust == 0)
return false;
$result = db_result_to_array($result);
return $result;
}
function display_checkout_form($c){
//here we create a form where the users current address details in the database are brought up. If these are diffrent then the user
//can edit them to the required shipping address.
?>
<br />
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<form method="post" action="purchase.php" enctype="multipart/form-data">
<tr><th colspan="2" bgcolor="CCCCCC">Shipping Address (only change if delivering to another address)</th></tr>
<p></p>
<tr>
<td align="left">First Name: </td>
<td><input name="ship_name" type="text" size="40" maxlength="20" value="<?php echo $cї'first_name']; ?>"></td>
</tr>
<tr>
<td align="left">Last Name: </td>
<td><input name="ship_surname" type="text" size="40" maxlength="20" value="<?php print $cї'surname']; ?>"></td>
</tr>
<tr>
<td align="left">Title: </td>
<td><input name="ship_initial" type="text" size="40"maxlength="4" value="<?php echo $cї'initial']; ?>"></td>
</tr>
<tr>
<td align="left">Address Line One: </td>
<td><input name="ship_address_1" type="text" size="40" maxlength="25" value="<?php echo $cї'address_line_one']; ?>"></td>
</tr>
<tr>
<td align="left">Address Line Two: </td>
<td><input name="ship_address_2" type="text" size="40" maxlength="25" value="<?php echo $cї'address_line_two']; ?>"></td>
</tr>
<tr>
<td align="left">City: </td>
<td><input name="ship_city" type="text" size="40" maxlength="30" value="<?php echo $cї'city']; ?>"></td>
</tr>
<tr>
<td align="left">County: </td>
<td><input name="ship_county" type="text" size="40" maxlength="30" value="<?php echo $cї'county']; ?>"></td>
</tr>
<tr>
<td align="left">Postcode: </td>
<td><input name="ship_postcode" type="text" size="40" maxlength="8" value="<?php echo $cї'postcode']; ?>"></td>
</tr>
</form>
</table>
<?
}
function calculate_shipping_cost($qty)
{
//if the qty of items is greater then the qty number in the database then we have a max charge of £20.00 delivery
//if it is less then 15 then we check where the $qty of items is the same as qty in the table and retireive the correct
//postage cost for that item.
if($qty > 15)
{
$shipping_cost = 20.00;
}else
$link_id = db_connect();
//check the database to get the price of delivery depending on the number of items brought.
$query = 'select * from shipping_costs where qty ="'.$qty.'"';
$result = mysql_query($query, $link_id);
$sc = mysql_fetch_array($result);
{
$shipping_cost = $scї'delivery_charge'];
}
return $shipping_cost;
}
function display_shipping($shipping_cost)
{
//displays the shipping cost in then checkout and payment forms
?>
<br />
<table width="600">
<tr>
<th align="left">Shipping</th><th align="left"><?php echo number_format($shipping_cost, 2); ?></th>
<th>Total including shipping</th>
<th align="right">£<?php echo number_format($shipping_cost+$_SESSIONї'total_price'], 2); ?></th>
</tr>
</table><br />
<?php
}
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jan 26, 2005 2:50 pm
there appears to be a possible logic error involving the else just before that query. Specifically, lack of braces to block in the query. However, the query may retrieve zero results as well. Make sure to check what query you are sending and what the database is really passing back.
mmc01ms
Forum Commoner
Posts: 97 Joined: Wed Dec 01, 2004 3:33 am
Location: Nottingham, UK
Post
by mmc01ms » Wed Jan 26, 2005 3:22 pm
one problem i have noticed is that it wasn't picking up $qty so it couldn't do the logic. I've sorted that by passing the $SESSION['items'] which is the number of items in the basket. I've also used some braces to lock in that query but still no luck. Any other debugging ideas?Query works fine as expected i echo the statement to see. changed code is
Code: Select all
<?php
//shopping_basket_fns.php written by Manpreet Sandhu 12/01/2005
session_start();
require_once('news_fns.php');
function display_cart($cart, $change = true, $images = 1)
{
//display what is in the shopping basket
$cart = $_SESSIONї'cart'];
$qty = $_SESSIONї'items'];
echo '<table border="0" width="100%" cellspacing="0">
<form action="show_cart.php" method="post">
<tr><th colspan="'. (1+$images) .'" bgcolor="#7b9815">Item</th>
<th bgcolor="#7b9815">Price</th><th bgcolor="#7b9815">Qty</th>
<th bgcolor="#7b9815">Total</th></tr>';
//display each item as a table row
foreach ($cart as $catno => $qty)
{
$vinyl = get_vinyl_details($catno);
print '<tr>';
if($images == true)
{
print '<td align="left">';
if(file_exists("images/$catno.jpg"))
{
$size = GetImageSize('images/'. $catno. '.jpg');
if($sizeї0] > 0 && $sizeї1] > 0)
{
print '<img src="images/'. $catno. '.jpg" ';
print 'width='. $sizeї0]/3 .'height = '.$sizeї1]/3 . '>';
}
}
else
print ' ';
print '</td>';
}
print '<td align="left">';
print '<font color="#44802c" size="3" face="Arial, Helvetica, sans-serif"><a href="show_vinyls.php?cat_no='.$catno.'">'.$vinylї'title'].'</a> - '.$vinylї'artist_id'].'</font>';
print '</td><td align="center"><font color="#44802c" size="3" face="Arial, Helvetica, sans-serif">£'.number_format($vinylї'price'], 2).'</font>';
print '</td><td align="center">';
//allowing change of qty
if($change == true)//if change is true then show input box for qty
echo'<input type="text" name="'.$vinylї'cat_no'].'" value="'.$qty.'" size="1">';
else
echo $qty;//else just show qty and total price
print '</td><td align="center"><font color="#44802c" size="3" face="Arial, Helvetica, sans-serif">£'.number_format($vinylї'price']*$qty, 2).'</font></td></tr>';
}
//display of total row
echo '<tr>
<th colspan="'. (2+$images) .'" bgcolor="#7b9815"> </td>
<th align="center" bgcolor="#7b9815">'.$_SESSIONї'items'].'</th>
<th align="center" bgcolor="#7b9815">£'.number_format($_SESSIONї'total_price'], 2).'</th>
</tr>';
//offer save feature
if($change == true)
{
echo '<tr>
<td colspan="'. (2+$images) .'" </td>
<td align="center">
<input type="hidden" name="save" value="true">
<input type="hidden" name="cat_no" value="$catno">
<input type="hidden" name="qty" value="$qty">
<input type="submit" value="Update Changes" alt="Update Changes">
</td>
<td></td>
</tr>';
}
echo '</form></table>';
}
function calculate_price($cart)
{
// sum total price for all items in shopping cart
$price = 0.0;
if(is_array($cart))
{
$link_id = db_connect();
foreach($cart as $catno => $qty)
{
$query = "select price from vinyls where cat_no='".$catno."'";
$result = mysql_query($query, $link_id);
if ($result)
{
//$row = mysql_fetch_row($result);
$item_price = mysql_result($result, 0, 'price');
//$item_price = $rowї'price'];
$price +=$item_price*$qty;
}
}
}
return $price;
}
function calculate_items($cart)
{
//total items in the cart which goes through the cart and adds up the quantities of each item to get the total number og items
$items = 0;
if(is_array($cart))
{
foreach($cart as $catno => $qty)
{
$items += $qty;
}
}
return $items;
}
function get_customer_details($customer_id)
{
$link_id = db_connect();
$query = "select first_name, surname, postcode, address_line_one , address_line_two, city, county, initial from customers where customer_id = '$customer_id'";
$result = @mysql_query($query, $link_id) or die ("There was a problem with this query.");
if (!$result)
return false;
$num_cust = @mysql_num_rows($result);
if($num_cust == 0)
return false;
$result = db_result_to_array($result);
return $result;
}
function display_checkout_form($c){
//here we create a form where the users current address details in the database are brought up. If these are diffrent then the user
//can edit them to the required shipping address.
?>
<br />
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<form method="post" action="purchase.php" enctype="multipart/form-data">
<tr><th colspan="2" bgcolor="CCCCCC">Shipping Address (only change if delivering to another address)</th></tr>
<p></p>
<tr>
<td align="left">First Name: </td>
<td><input name="ship_name" type="text" size="40" maxlength="20" value="<?php echo $cї'first_name']; ?>"></td>
</tr>
<tr>
<td align="left">Last Name: </td>
<td><input name="ship_surname" type="text" size="40" maxlength="20" value="<?php print $cї'surname']; ?>"></td>
</tr>
<tr>
<td align="left">Title: </td>
<td><input name="ship_initial" type="text" size="40"maxlength="4" value="<?php echo $cї'initial']; ?>"></td>
</tr>
<tr>
<td align="left">Address Line One: </td>
<td><input name="ship_address_1" type="text" size="40" maxlength="25" value="<?php echo $cї'address_line_one']; ?>"></td>
</tr>
<tr>
<td align="left">Address Line Two: </td>
<td><input name="ship_address_2" type="text" size="40" maxlength="25" value="<?php echo $cї'address_line_two']; ?>"></td>
</tr>
<tr>
<td align="left">City: </td>
<td><input name="ship_city" type="text" size="40" maxlength="30" value="<?php echo $cї'city']; ?>"></td>
</tr>
<tr>
<td align="left">County: </td>
<td><input name="ship_county" type="text" size="40" maxlength="30" value="<?php echo $cї'county']; ?>"></td>
</tr>
<tr>
<td align="left">Postcode: </td>
<td><input name="ship_postcode" type="text" size="40" maxlength="8" value="<?php echo $cї'postcode']; ?>"></td>
</tr>
</form>
</table>
<?
}
function calculate_shipping_cost($items)
{
//$qty = $_GETї'qty'];
//if the qty of items is greater then the qty number in the database then we have a max charge of £20.00 delivery
//if it is less then 15 then we check where the $qty of items is the same as qty in the table and retireive the correct
//postage cost for that item.
if($items > 15)
{
$shipping_cost = 20.00;
}else
{
if($items <= 15)
{
$link_id = db_connect();
//check the database to get the price of delivery depending on the number of items brought.
$query = 'select * from shipping_costs where qty ="'.$items.'"';
echo $query;
$result = mysql_query($query, $link_id);
$sc = mysql_fetch_array($result);
{
$shipping_cost = $scї'delivery_charge'];
}
}
}
return $shipping_cost;
}
function display_shipping($shipping_cost)
{
//displays the shipping cost in then checkout and payment forms
?>
<br />
<table width="600">
<tr>
<th align="left">Shipping</th><th align="left"><?php echo number_format($shipping_cost, 2); ?></th>
<th><?php echo $qty; ?>Total including shipping</th>
<th align="right">£<?php echo number_format($shipping_cost+$_SESSIONї'total_price'], 2); ?></th>
</tr>
</table><br />
<?php
}
?>
Code: Select all
<?php
session_start(); //must start a session for cart
//$qty = $_GETї'qty'];
$items = $_SESSIONї'items'];
//checkout.php written by Manpreet Sandhu 26/01/2005
require('page.inc'); //page class
require_once('shopping_basket_fns.php');
$checkout = new Page();//create new page object
$checkout -> Display();//use function display from page class
display_main_menu(); //display side bar menu
$link_id = db_Connect();//connect the database
//query the database to retrieve all information out of the database regarding the current customer using the
//registered session variable which is their customer id.
$query = mysql_query("SELECT * FROM customers WHERE customer_id='".$_SESSIONї'customer_id']."'",$link_id);
$c = mysql_fetch_array($query);//fetch the results of the query and for them in an array and assign the value $c
//to pass through to the display_checkout_form function.
//echo $qty;
//$items
print '<table width="600">';
print '<center><th align="center" colspan="6">';
print "Checkout";
print '</th></center>';
print '<tr>';
print '<td>';
print "ї<a href='show_cart.php'>Back</a>]";
print "ї<a href='vinyls.php'>Search for more vinyls</a>]";
print '</td>';
print '</tr>';
print '<table>';
print '<p></p>';
if($_SESSIONї'cart']&&array_count_values($_SESSIONї'cart']))
{//if session values exist then display cart with the items and the checkout form else echo message
display_cart($_SESSIONї'cart'], false, 0);
display_shipping(calculate_shipping_cost($items));
display_checkout_form($c);
}
else
print 'There are no items in your cart';
do_html_footer();
?>
patrikG
DevNet Master
Posts: 4235 Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK
Post
by patrikG » Wed Jan 26, 2005 5:37 pm
Sorry for not giving you concrete help, but I simply don't want to read through 300 lines of PHP mixed with HTML.
You would make your life much simpler (and your programs much less error-prone), if you thought about seperating logic and display. Having functions return HTML beats the purpose of using functions in all but one respect: the one project you're designing your functions for. Next project, different functions. Why not move more towards creating an application rather than a generating HTML pages? It will help you
very much in the future. Maybe even start reading up on object oriented programming - which at first doesn't look different to using functions at all. Or maybe think about using a templating engine as well.
It would make life easier for everyone
hunterhp
Forum Commoner
Posts: 46 Joined: Sat Jan 22, 2005 5:20 pm
Contact:
Post
by hunterhp » Wed Jan 26, 2005 8:21 pm
I believe the problem is because you didn't make a mysql_query
You're suppose to do.
$query = mysql_query($query, $link_id);
//Then
$query = mysql_fetch_array($query);
Edit: Oops, didn't read that part where you passed the result.
Maybe if you change from single quotes to double quotes you get better results.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jan 26, 2005 8:57 pm
folks... the issue was resolved via IM. Consider this closed.
For anyone curious, the query was buggy.