Skip to main content

Forums

This topic contains 1 reply, has 0 voices, and was last updated by  LaurelBrittany 6 years, 2 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #45143

    LaurelBrittany
    Participant

    I’m getting this error for my shopping cart: Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or ‘$’ in /home/lpehrson/public_html/webdev/my_cart.php on line 89

    This is what my shopping cart code is:

    <div id="right">
    <h2>My Cart</h2>
    <table width="100%">
    <tr>
    <th>Item Name</th>
    <th>Description</th>
    <th>Price</th>
    <th>Actions</th>
    </tr>
    <?php
    $cart = $_COOKIE;
    if ($cart)
    {
    $i = 1; // Set the counter to 1
    include('includes/dbc.php');
    $items = explode(',', $cart); //Seperate each ID by comma
    foreach($items AS $item) // Create the $item variable which will act as an individual ID
    {
    $sql = "SELECT * FROM products where id = '$item'";
    $result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
    while($row=mysql_fetch_assoc($result))
    {
    echo '<tr>';
    echo '<td align="left">';
    echo $row;
    echo '</td>';
    echo '<td align="left">';
    echo $row;
    echo '</td>';
    echo '<td align="left">';
    echo $row;
    echo '</td>';
    echo '<td align="left">';
    if($1==1)
    {
    echo '<a href="my_cart.php?remove_id_1='.$row.'">Remove From Cart</a>';
    }
    else
    {
    echo '<a href="my_cart.php?remove_id='.$row.'">Remove From Cart</a>';
    }
    echo '</td>'
    echo '</tr>';
    }
    $i++; //Increments the counter by 1
    }
    }
    ?>
    </table>
    <form method="post" action="<?php $_SERVER;?>">
    <input type="submit" name="clear" value="Empty Shopping Cart">
    </form>
    Check out this Pen!

    You can find all of my source files here: http://lpehrson.mydevryportfolio.com/webdev/LPehrsonWeek45.zip

    My Shopping cart is here: http://lpehrson.mydevryportfolio.com/webdev/products.php

    #137369

    __
    Participant

    > `$1`

    You can’t have variable names that start with digits in PHP.

    *****
    A suggestion: read the error messages, look at the file/ line number it describes, and see what’s wrong. With parse errors, PHP’s error messages are actually very useful, and almost always lead directly to the problem.

    In this case, you wrote `$1` instead of `$i`, so PHP was confused because `1` cannot follow `$` – only identifiers (for a [variable name](http://php.net/manual/en/language.variables.basics.php)) or another `$` (for [variable variables](http://php.net/manual/en/language.variables.variable.php)).

    You can also google simple error messages like this to get a good idea of what the problem might be.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

icon-link icon-logo-star icon-search icon-star