undefined variable

I inserted the default value for $custid = 0;     before the first 'if'.   It worked.

However, my previous  carts are not emptied and there's a problem with the total - it only gives the total of the last cart.
And it's now giving this error  :
Notice: Undefined variable: customers_custnum in C:\Xamp\htdocs\chapter15\checkout3.php on line 96
(which is '$total', )
Willem NorvalstudentAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
It's the same problem but with a different variable.  You are defining it inside an 'if' and then trying to use it whether it is defined or not.  You have to define a value for a variable before you can use it.  I also do not see any purpose for using $customers_custnum = $custid;.  Just use $custid.

Most of my PHP pages start out with a long list of variable definitions to make sure things like this do not happen.  In my code, lines like this...
$firstname = $_POST['firstname'];

Open in new window

are done like this:
if (!isset($_POST['firstname']))  $firstname = ''; else $firstname = $_POST['firstname'];

Open in new window

This makes sure that the POST data always has a defined value.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Willem NorvalstudentAuthor Commented:
The error message problem was solved.
The other part of the problem remains  -  why is the cart not emptied of previous orders ?
Dave BaldwinFixer of ProblemsCommented:
I don't know.  Is that the temporary file (createtemp.php)?  There is nothing about that in the code you posted on the other question.
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Willem NorvalstudentAuthor Commented:
Yes, the temporary file was created by createtemp.php,  it's in my database :
CREATE TABLE carttemp(
          carttemp_hidden INT(10) NOT NULL AUTO_INCREMENT,
          carttemp_sess CHAR(50) NOT NULL,
          carttemp_prodnum CHAR(5) NOT NULL,
          carttemp_quan INT(3) NOT NULL,
          PRIMARY KEY (carttemp_hidden),
Willem NorvalstudentAuthor Commented:
Here's the MySQL database copy
Willem NorvalstudentAuthor Commented:
I found this feedback on the textbook's forum on the same problem (couldn't quite make out what he means) :
"Please check this !!!!
Notice: a seeion had already been started - ignoring session_start() in c:\inetpub\wwwroot\cms\cart.php on line 3.
the code line reads session_start(); on line 3 of the cart.php page.

2. Notice: use of undefined constant total - assumed 'total' in c:\inetpub\wwwroot\cms\cart.php on line 89.
the code line reads $total = $extprice + $total; on line 89 of the cart.php page.

secondly i also noticed the second problem on the checkout2.php page which reads

Notice: use of undefined constant total - assumed 'total' in c:\inetpub\wwwroot\cms\checkout2.php on line 274.
the code line reads $total = $extprice + $total; on line 274 of the cart.php page.

thirdly, i noticed that the final total is not often correct if you purchase large amount of goods for example i tried to purchase 300 CBA Coffee Mug which cost 8.95 each with extended price which is 2,685.00 and Small Grappling Hook which cost 139.95 each with extending price which is 2, 379.15 and noticed that the total before shipping is reading 4.00 and on the confirmation page its read thesame. i mean 4.00 which is not correct. "
Dave BaldwinFixer of ProblemsCommented:
What book is this?
Willem NorvalstudentAuthor Commented:
Beginning PHP5, Apache, MySQL Web Development
Willem NorvalstudentAuthor Commented:
By Wrox books
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.