Bhame Posted March 8, 2013 Share Posted March 8, 2013 Notice: Undefined index: command in D:\xampp\htdocs\cart\products.php on line 5 <?phpinclude("includes/db.php");include("includes/functions.php");if($_REQUEST['command']=='add' && $_REQUEST['productid']>0){ <<Error$pid=$_REQUEST['productid'];addtocart($pid,1);header("location:shoppingcart.php");exit();}?> Notice: Undefined index: command in D:\xampp\htdocs\cart\shoppingcart.php on line 5Notice: Undefined index: command in D:\xampp\htdocs\cart\shoppingcart.php on line 8Notice: Undefined index: command in D:\xampp\htdocs\cart\shoppingcart.php on line 11 <?phpinclude("includes/db.php");include("includes/functions.php");if($_REQUEST['command']=='delete' && $_REQUEST['pid']>0){ <<<Errorremove_product($_REQUEST['pid']);}else if($_REQUEST['command']=='clear'){ <<<<Errorunset($_SESSION['cart']);}else if($_REQUEST['command']=='update'){ <<<<Error$max=count($_SESSION['cart']);for($i=0;$i<$max;$i++){$pid=$_SESSION['cart'][$i]['productid'];$q=intval($_REQUEST['product'.$pid]);if($q>0 && $q<=999){$_SESSION['cart'][$i]['qty']=$q;}else{$msg='Some proudcts not updated!, quantity must be a number between 1 and 999';}}}?> Quote Link to comment https://forums.phpfreaks.com/topic/275398-please-help-me-in-my-shopping-cart/ Share on other sites More sharing options...
gizmola Posted March 8, 2013 Share Posted March 8, 2013 A notice is not an error. It is a warning. Notices are typically used during development to help perfect code by pointing out non-fatal issues like the ones in this script. The notices you are receiving can be avoided using isset, but it is not unusual for scripts to do the types of comparisons that are producing the notices you show. Those comparisons will still work properly because they will evaluate to false, even though the variables in the comparison do not actually exist if rhw url parameters are not passed into the $_GET or $_REQUEST. You can turn off the display of notices by changing that setting in the php.ini, or in the script you can turn down the level or reporting using: error_reporting(E_ALL ^ E_NOTICE); Quote Link to comment https://forums.phpfreaks.com/topic/275398-please-help-me-in-my-shopping-cart/#findComment-1417446 Share on other sites More sharing options...
Bhame Posted March 8, 2013 Author Share Posted March 8, 2013 sir? how can i turn off the display error? i can't find the php.ini only i can see is "php.ini-development" , "php.ini-production". can you give me the exact direction to fixed it? plzzzz? Quote Link to comment https://forums.phpfreaks.com/topic/275398-please-help-me-in-my-shopping-cart/#findComment-1417450 Share on other sites More sharing options...
mostafatalebi Posted March 8, 2013 Share Posted March 8, 2013 (edited) Hey buddy just add one line on top of your line, below session_start(); in your case just go to topmost, since you do not have session_start() error_reporting(E_ERROR | E_WARNING | E_PARSE); if you change E_WARNING to E_NOTICE or add E_NOTICE then you will receive Notices. Edited March 8, 2013 by mostafatalebi Quote Link to comment https://forums.phpfreaks.com/topic/275398-please-help-me-in-my-shopping-cart/#findComment-1417452 Share on other sites More sharing options...
gizmola Posted March 8, 2013 Share Posted March 8, 2013 Create a script in your webroot that has this simple code: Point your browser to that page, and it will show you lots of information about your php setup including the location of the ini files. Quote Link to comment https://forums.phpfreaks.com/topic/275398-please-help-me-in-my-shopping-cart/#findComment-1417453 Share on other sites More sharing options...
NuneRex Posted March 27, 2013 Share Posted March 27, 2013 Hello. I have the same issue as stated above, but my question is how do I correct the issue? I do not want to cover it up or hide it, I want to fix it. Looking at the code that I being used, for I did not write it, but am using is from a tutorial: // This is placed after the session_start(); if($_REQUEST['command']=='clear'){ unset($_SESSION['cart']); //This is placed in the <head> function clear_cart(){ if(confirm('This will empty your shopping cart, continue?')){ document.form1.command.value='clear'; document.form1.submit(); } } //And this is used at the bottom of the form <input type="button" value="Clear Cart" onclick="clear_cart()"> What am I missing, why do I still get the error: Notice: Undefined index: command in /var/www/html/TestFolder/functions_ordering.php on line 5 Thank you and have a great day! Quote Link to comment https://forums.phpfreaks.com/topic/275398-please-help-me-in-my-shopping-cart/#findComment-1421484 Share on other sites More sharing options...
PaulRyan Posted March 27, 2013 Share Posted March 27, 2013 if(isset($_REQUEST['command']) && $_REQUEST['command'] == 'clear'){ Quote Link to comment https://forums.phpfreaks.com/topic/275398-please-help-me-in-my-shopping-cart/#findComment-1421485 Share on other sites More sharing options...
NuneRex Posted March 28, 2013 Share Posted March 28, 2013 Hello PaulRyan, I thank you for your response. I have tried isset and the notice does clear however the only thing that happens now is the popup window and then nothing. I expected the next page to show up and the form to clear but it does not. //Beginning of page <?php //Start the session session_start(); if(isset($_REQUEST['command']) && $_REQUEST['command'] == 'clear'){ unset($_SESSION['cart']); header("location:product_page.php"); } ?> //Head of HTML <script language="javascript"> function clear_order(){ if(confirm('This will empty your shopping cart, continue?')){ document.submit_order.command.value='clear'; document.submit_order.submit(); } } </script> //Button in bottom of form <input type="button" value="CLEAR Order" onclick="clear_order()"> Is there anything else that I am doing wrong? Thank you for your time and assistance. Quote Link to comment https://forums.phpfreaks.com/topic/275398-please-help-me-in-my-shopping-cart/#findComment-1421599 Share on other sites More sharing options...
PaulRyan Posted March 28, 2013 Share Posted March 28, 2013 Use exit after your header redirect line. Quote Link to comment https://forums.phpfreaks.com/topic/275398-please-help-me-in-my-shopping-cart/#findComment-1421608 Share on other sites More sharing options...
NuneRex Posted March 28, 2013 Share Posted March 28, 2013 Hello Paul, I placed it here as I understood you, with out any change. The page stays with the information still on the page and does not redirect. //Beginning of page <?php //Start the session session_start(); if(isset($_REQUEST['command']) && $_REQUEST['command'] == 'clear'){ unset($_SESSION['cart']); header("location:product_page.php"); exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/275398-please-help-me-in-my-shopping-cart/#findComment-1421613 Share on other sites More sharing options...
PaulRyan Posted March 28, 2013 Share Posted March 28, 2013 (edited) Well then the if statement isn't firing. Make sure the variable you are checking is exactly what you're after, use var_dump after the session start function. var_dump($_REQUEST['command']); Edited March 28, 2013 by PaulRyan Quote Link to comment https://forums.phpfreaks.com/topic/275398-please-help-me-in-my-shopping-cart/#findComment-1421618 Share on other sites More sharing options...
NuneRex Posted March 28, 2013 Share Posted March 28, 2013 That is what I was thinking, but I keep getting the popup message after I click on the (CLEAR Order) button and then nothing. Here is what I typed as I understood you. //Beginning of page <?php //Start the session session_start(); var_dump($_REQUEST['command']); if(isset($_REQUEST['command']) && $_REQUEST['command'] == 'clear'){ unset($_SESSION['cart]); header("location:product_page.php"); exit(); } ?> The response I got was: Notice: Undefined index: command in /var/www/... on line 4. NULL So it looks like the same issue I had before, except this time it tells me NULL. Quote Link to comment https://forums.phpfreaks.com/topic/275398-please-help-me-in-my-shopping-cart/#findComment-1421630 Share on other sites More sharing options...
NuneRex Posted March 28, 2013 Share Posted March 28, 2013 Any other ideas? Thank you very much for your efforts. Quote Link to comment https://forums.phpfreaks.com/topic/275398-please-help-me-in-my-shopping-cart/#findComment-1421641 Share on other sites More sharing options...
PaulRyan Posted March 28, 2013 Share Posted March 28, 2013 That means that the $_REQUEST['command'] is not being sent to the page as expected. Which page is sending the "command"? Because there is some error on that page that isn't sending the data as it should. Quote Link to comment https://forums.phpfreaks.com/topic/275398-please-help-me-in-my-shopping-cart/#findComment-1421642 Share on other sites More sharing options...
NuneRex Posted March 28, 2013 Share Posted March 28, 2013 This is the page that is sending the command from the form button at the bottom. <?php //ordering.php page2 //Start the session session_start(); var_dump($_REQUEST['command']); if(isset($_REQUEST['command']) && $_REQUEST['command'] == 'clear'){ unset($_SESSION['cart']); header("location:product_page.php"); exit(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <script type="text/javascript"> function getOrderTotal() { var icost = document.product_form.unitCost1.value; var iqty = document.product_form.qty1.value; var recurrency = '^[0-9]{1,5}\.[0-9]{2}$'; var reitems = '^([1-9])([0-9]{0,2})$'; if(!icost.match(recurrency)) { alert('Please provide an item cost in 0.00 format!'); } else if(!iqty.match(reitems)) { alert('Please provide a quantity of 1 to 999!'); } else { var itotal = (icost * iqty); itotal *= 100; itotal = Math.ceil(itotal); itotal /= 100; if(itotal.toFixed) { itotal = itotal.toFixed(2); } document.getElementById('totalCost1').value = itotal; } } </script> <head> <title>Order Form</title> <script language="javascript"> function clear_order(){ if(confirm('This will empty your shopping cart, continue?')){ document.subtm_order.command.value='clear'; document.subtm_order.submit(); } } </script> </head> <body style="background: #336699; margin-top: 8px; margin-left: 8px;"> <h1 align="center">Order Form</h1> <?php date_default_timezone_set('America/Los_Angeles'); $ord_date=date('M j, Y H:i'); //If we have previously initiated a session in order_product.php, the shopping cart is //defined as an associative array, $_SESSION['cart']. //We first need to check if the $_SESSION['cart'] variable has been defined, as it //won't be if the user has come straight to this page. //Top of the order form information echo '<div align="center"><form name="subtm_order" method="post"> <table border="0" id="requestor_info" summary="Table holds SubTM Ordered Parts information"> <tbody> <thead><tr><th>Requesting Facility<br> <input name="facility" type="text" id="facility" value="SubTM Bangor" size="11" readonly="readonly"></th> <th>Requester Name<br> <input name="lname" type="text" id="lname" style="text-align: center" size="10" value="'.$_SESSION['SESS_MEMBER_LNAME'].'"></th> <th>Today\'s Date<br> <input align="center" type="text" name="ord_date" value="'.$ord_date.'" readonly="readonly" size="14"></th></tr> </thead> </tbody> </table>'; //We also need to check if there are currently any items in the shopping cart. if (!isset($_SESSION['cart']) || (count($_SESSION['cart']) == 0)) { echo '<p>Your order form is woefully empty!</p>'; } else { echo '<table border="1" cellpadding="5px" cellspacing="1px" style="font-family:Veranda, Geneva, sans-serif; font-size:11px; background-color:#E1E1E1"> <tr bgcolor=\"#FFFFFF\" style=\"font-weight:bold\"> <th>Row</th> <th>Unit Cost</th> <th>Qty</th> <th><div title="bx, ea, ft, etc.">Unit</div></th> <th>Description</th> <th>Part Number</th> <th><div title="AC-1, AC-2, COAET, etc.">Location where <br>item is used</div></th> <th>Rack or<br>Machine Info</th> <th>Function performed<br>by Hardware</th> <th>Total Cost</th> <th>Sources / Links <br>Please paste below</th></tr>'; $total = 0; $i=1; //We iterate over all the items in $_SESSION['cart']. //Each item represents a "row," or a single product to buy, in the shopping cart. foreach($_SESSION['cart'] as $item) { //Recall that the format of the $item associative array is the same as the one //defined in add.php, since the array has simply been passed to this page //via the $_SESSION variable. echo "<tr bgcolor=\"#FFFFFF\" style=\"font-weight:bold\"> <td>$i</td> <td>\${$item['unitCost']}</td> <td>{$item['ord_qty']}</td> <td>{$item['unit']}</td> <td>{$item['desc']}</td> <td>{$item['partNo']}</td> <td>{$item['location']}</td> <td>{$item['rackUnit']}</td> <td>{$item['hdwrFunct']}</td> <td>$".number_format(($item['unitCost'] * $item['ord_qty']),2)."</td> <td>{$item['supplierUrl']}</td> </tr>"; $i++; $total += ($item['unitCost'] * $item['ord_qty']); }; } ?> <tr><td colspan="3"><b><strong>Grand total: </strong>$<?php echo number_format($total,2)?></b></td> <td colspan="8" align="right"> <input type="button" value="CLEAR Order" onclick="clear_order()"> <input type="button" value="Order more" onclick="window.location='product_page.php'"> <input type="button" value="Place Order" onclick="window.location='submit_order.php'"></td></tr> </table></form></div> <!-- <hr /> --> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/275398-please-help-me-in-my-shopping-cart/#findComment-1421669 Share on other sites More sharing options...
NuneRex Posted March 28, 2013 Share Posted March 28, 2013 There are two other buttons that allow it the user to continue ordering items and a button that is not implemented yet to submit the order. The $_REQUEST comes from the same page that I am ordering on. If that is not allowed please let me know and I will place it onto a separate page. Quote Link to comment https://forums.phpfreaks.com/topic/275398-please-help-me-in-my-shopping-cart/#findComment-1421672 Share on other sites More sharing options...
PaulRyan Posted March 28, 2013 Share Posted March 28, 2013 (edited) You don't have an input in your form with the name "command" you need to add one in. <input type="text" name="command"> Edit - Please use the code tags in future to show code. Edited March 28, 2013 by PaulRyan Quote Link to comment https://forums.phpfreaks.com/topic/275398-please-help-me-in-my-shopping-cart/#findComment-1421681 Share on other sites More sharing options...
NuneRex Posted March 28, 2013 Share Posted March 28, 2013 My apologies, I will find the code tags. Thank you very much you were correct that solved my problem. The redirect works, the values are cleared and the page is ready for reuse! Once again, many thanks! xD Quote Link to comment https://forums.phpfreaks.com/topic/275398-please-help-me-in-my-shopping-cart/#findComment-1421684 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.