undefined variable error help

Discussion in 'PHP' started by co.ador, Sep 5, 2009.

  1. #1
    Total: $
    Notice: Undefined variable: totalCost in C:\wamp\www\shoes\stores\cart.php on line 151
    0.00

    <tr>
    <td colspan="2">
    <font face="verdana" size="1" color="black">
    <a href="itemdetails.php">&lt;&lt; Keep Shopping</a></font></td>
    <td colspan="2">
    <font face="verdana" size="2" color="black">
    <b>Total: $<?php echo number_format($totalCost, 2, ".", ","); ?></b>// line 151 
    </font></td>
    </tr>
    <tr>
    PHP:
    What could that be and where could I define it
     
    co.ador, Sep 5, 2009 IP
  2. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Just say $totalCost = ''; somewhere before you call it in numberformat (or anywhere else before it's defined). strictly speaking you don't have to, it's only a warning. or you could say
    @number_format($totalCost, 2, ".", ",");
    PHP:
    or at the start of your php script you could use:

    error_reporting(0);
    PHP:
     
    Last edited: Sep 5, 2009
    szalinski, Sep 5, 2009 IP
  3. sarikabtech

    sarikabtech Well-Known Member

    Messages:
    186
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    108
    #3
    Use isset($totalCost) to check if it is defined or not. If yes then put ur code else do something else.
     
    sarikabtech, Sep 6, 2009 IP
  4. Amator

    Amator Well-Known Member

    Messages:
    1,424
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #4
    You should give more info about the page / script. What are you trying to do ? Where io you calculate $totalCost ?
     
    Amator, Sep 6, 2009 IP