Jump to content

Please help me in my Shopping Cart


Bhame

Recommended Posts

Notice: Undefined index: command in D:\xampp\htdocs\cart\products.php on line 5
 
 
<?php
include("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 5

Notice: Undefined index: command in D:\xampp\htdocs\cart\shoppingcart.php on line 8

Notice: Undefined index: command in D:\xampp\htdocs\cart\shoppingcart.php on line 11
 
 
 
 
<?php
include("includes/db.php");
include("includes/functions.php");

if($_REQUEST['command']=='delete' && $_REQUEST['pid']>0){ <<<Error
remove_product($_REQUEST['pid']);
}
else if($_REQUEST['command']=='clear'){ <<<<Error
unset($_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';
}
}
}

?>
 
Link to comment
Share on other sites

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);
Link to comment
Share on other sites

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 by mostafatalebi
Link to comment
Share on other sites

  • 3 weeks later...

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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();
}
?>
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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"


<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>
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.