Page 1 of 1

Notice: Undefined index: buttonClicked in

Posted: Fri Sep 23, 2016 5:37 am
by jonnyfortis
i have a checkout with two buttons but then the user is sent from the cart to the checkout im getting the following error

Code: Select all

Notice: Undefined index: buttonClicked in /home/erggnfr/public_html/web/AW16/checkout.php on line 259

Notice: Undefined index: buttonClicked in /home/erggnfr/public_html/web/AW16/checkout.php on line 288

the code is

line 259:

Code: Select all

if (is_numeric($_POST['buttonClicked']) && ($_POST['buttonClicked']==1)) {
288:

Code: Select all

elseif (is_numeric($_POST['buttonClicked']) && ($_POST['buttonClicked']==2)){

Re: Notice: Undefined index: buttonClicked in

Posted: Fri Sep 23, 2016 6:19 am
by pbs
Try this

Code: Select all

$buttonClicked = isset($_POST['buttonClicked']) ? $_POST['buttonClicked'] : 0; // you can set default value instead of 0

if ($buttonClicked == 1)
....
.....

Re: Notice: Undefined index: buttonClicked in

Posted: Fri Sep 23, 2016 6:47 am
by jonnyfortis
pbs wrote:Try this

Code: Select all

$buttonClicked = isset($_POST['buttonClicked']) ? $_POST['buttonClicked'] : 0; // you can set default value instead of 0

if ($buttonClicked == 1)
....
.....

where to i put this in context the the previous script?

Re: Notice: Undefined index: buttonClicked in

Posted: Fri Sep 23, 2016 6:59 am
by Celauran
Before your is_numeric checks. This first checks if it exists and, if not, initializes it to 0. You could even cast it to an int and remove the is_numeric checks altogether, depending on your requirements.

Re: Notice: Undefined index: buttonClicked in

Posted: Fri Sep 23, 2016 11:15 am
by Christopher
Maybe something like this would be better:

Code: Select all

if (isset($_POST['buttonClicked']) {
    switch($_POST['buttonClicked']) {
    case '1':
        // code if 1
        break;
    case '2':
        // code if 2
        break;
    default:
        // invalid value error
    }
} else {
    // not set error
}