undefined variable

This eCommerce exercise is giving me an error, please see if you can help ?
Everything works fine until I do the final checkout.

These are the error lines :
Notice: Undefined variable: custid in C:\Xamp\htdocs\chapter15\checkout3.php on line 71
I thought it is already defined in line 66 ? (or is mysql_insert_id() not imported properly ?)

Notice: Undefined variable: customers_custnum in C:\Xamp\htdocs\chapter15\checkout3.php on line 90
         customers_custnum  is from the eCommerce database

Another problem is that the temporary file (createtemp.php) is not emptied and items keep piling up every time I go back to test.
Perhaps this problem will dissappear when the previous problem is solved ?
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:
if ($rows >= 1) then 'custid' will not be defined because it is inside that 'if' statement but you are still trying to use 'custid' in the next 'if'.  I would define a default value for 'custid' somewhere earlier in the file that will make it work the way you want.  Maybe... $custid = 0; before the first 'if'.

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:
Thanks Dave, I'll try that
Willem NorvalstudentAuthor Commented:
Hi Dave,
I defined a default value for  $custid = 0;  before the first 'if'.
It seemed to have worked,.

but now I'm getting this error notice :
Notice: Undefined variable: customers_custnum in C:\Xamp\htdocs\chapter15\checkout3.php on line 96

Also, the items keep piling up and it only totals the last transaction
Willem NorvalstudentAuthor Commented:
Hi Dave,
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', )
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.
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.