RobLamb Posted July 29, 2009 Share Posted July 29, 2009 Good day everyone I have a page that generates a cart on a site. Basically what I want is that if the values of the size2 and 3 are empty then they must be hidden and if they are populated then be shown. I have tried a couple of options and am not winning! Could someone please help me out on this one urgently. Then... my next issue is that I need to mail this off to a client and am battling with that too becasue I am unsure on how to do this when the names of my fields are based on the products id!! Some help and advise would be greatly appreciated... here is the code I have....please..any urgent help would be appreciated! <?php function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return '<p>You have 0 in your shopping cart</p>'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>'; } } function showCart() { global $db; //echo $db; $cart = $_SESSION['cart']; //echo $cart; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; $output[] = '<table border="0">'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM tbl_products WHERE prod_id = '.$id; //echo $sql2; $result = $db->query($sql); $row = $result->fetch(); extract($row); $output[] = '<tr>'; $output[] = '<td width="50px" align="center"><img src="prodImages/'.$prod_image.'" width="30px" height="30px"></td>'; $output[] = '<td nowrap=nowrap> </td>'; $output[] = '<td nowrap=nowrap>'.$prod_name.'</td>'; $output[] = '<td nowrap=nowrap>'.$size1.' @ R'.$price.'<input onclick="KW_calcForm(\'total'.$id.'\',100,-1,\'#price'.$id.'\',\'*\',\'#qty'.$id.'\')" name="price'.$id.'" type="radio" value="'.$price.'" checked="checked"/> '.$size2.' @ R'.$price2.'<input onclick="KW_calcForm(\'total'.$id.'\',100,-1,\'#price'.$id.'\',\'*\',\'#qty'.$id.'\')" name="price'.$id.'" type="radio" value="'.$price2.'" /> '.$size3.' @ R'.$price3.'<input onclick="KW_calcForm(\'total'.$id.'\',100,-1,\'#price'.$id.'\',\'*\',\'#qty'.$id.'\')" name="price'.$id.'" type="radio" value="'.$price3.'" /></td>'; $output[] = '<td nowrap=nowrap><input onblur="KW_calcForm(\'total'.$id.'\',100,-1,\'#price'.$id.'\',\'*\',\'#qty'.$id.'\')" name="qty'.$id.'" type="text" value="'.$qty.'" size="3" maxlength="5" /></td>'; $output[] = '<td nowrap=nowrap> </td>'; $output[] = '<td nowrap=nowrap><input type="text" name="total'.$id.'" size="5" /></td>'; $output[] = '<td nowrap=nowrap><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>'; $total += $price * $qty; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = ' '; $output[] = '<div><button type="submit" class="button">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>Your shopping cart is empty.</p>'; } return join('',$output); } ?> Link to comment https://forums.phpfreaks.com/topic/167923-help-with-if-statement-and-then-mailing/ Share on other sites More sharing options...
diondev Posted July 29, 2009 Share Posted July 29, 2009 <?php $size2 = 'value'; $size3 = 'value'; if (!empty($size2) && !empty($size3)) { // the sizes are not empty } else { // the sizes are empty } mail('[email protected]', 'Email title', 'Email body goes here', 'From: [email protected]'); ?> Link to comment https://forums.phpfreaks.com/topic/167923-help-with-if-statement-and-then-mailing/#findComment-885724 Share on other sites More sharing options...
RobLamb Posted July 30, 2009 Author Share Posted July 30, 2009 Hi Diondev Thanks for the advice on the size issues.... I have sorted that out...many thanks. But, my issue now is this... the adding or mailing off of this is my problem... the forms obviously builds dynamically based on the number of products that are added to it... and I am stumped how I am going to get this to the client. My first prize would be to add it to a database and then let them view the order in the admin backend BUT how should I be doing this?? Should I be trying to add the whole basket into one field?? I will attach my functions.inc file that builds the cart and then the cart page itself.... please could you advise me!! [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/167923-help-with-if-statement-and-then-mailing/#findComment-886802 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.