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?
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.
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.
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.