Raquel Shelton
Raquel Shelton

Reputation: 1

Why are my brackets turning into part of my print statement?

Trying to display the results of my post array. For line

print "<tr><td>$prodqty</td>......" 

I need my {$gear{prodnum}[1]} to have that last bracket close out the array element. But for some reason the final closing bracket becomes part of my print statement (for anyone familiar with NetBeans, that bracket turns orange instead of black like it's supposed to be) and since I have a few if/else statements, the closing bracket gets moved to further down the lines (particularly after a ; which I don't understand) and I can't figure out how to get that array element to close.

I have tried both {$gear{$prodnum}[1]} and {$gear{$prodnum[1]}} and either way it will not work. I also tried () instead of brackets for $prodnum.

My professor was the one who helped me write that section and it was working until I tried to add more if statements and then it stopped.

if(array_key_exists('submit',$_POST))
{
    echo "<table><table align='center'><th colspan='3'>Total</th><tr>
<td>Quantity</td><td>Item</td><td>Extended Price</td></tr>";

    foreach($_POST['qty'] as $prodnum=>$prodqty){

        if($prodqty>0){

            print "<tr><td> $prodqty </td> <td>{$gear{$prodnum}[1]**}**</td>";
            print "<td>".($prodqty*$gear{$prodnum}[3])."</td></tr>";
        }
    };

elseif($prodqty==null)
{;
}

else {
    echo "Please enter a quantity.";
}
};

Ideally I would like the prodqty to go after the prodnum, but it would not work that way. Also any suggestions on how to print the results of the $POST that have quantities added, and forgetting those that do not, will be greatly appreciated. I'm trying to write the if statements to require the submitter to enter a number (no letters or words) and leave the other array elements out if they did not enter a quantity for them. Thank you!

Upvotes: 0

Views: 47

Answers (1)

Jonathan K
Jonathan K

Reputation: 550

Your if and else placement seemed mis-aligned. Tried to reconstruct your statement to best i think you are trying to achieve

if(array_key_exists('submit',$_POST))
{
    echo "<table><table align='center'><th colspan='3'>Total</th><tr>
    <td>Quantity</td><td>Item</td><td>Extended Price</td></tr>";

    foreach($_POST['qty'] as $prodnum=>$prodqty){

       if($prodqty>0){

          print "<tr><td> $prodqty </td> <td>".$gear[$prodnum][1]."</td>";
                print "<td>".($prodqty*$gear[$prodnum][3])."</td></tr>";

       } elseif($prodqty==null)
       {
       }
    };
} else {
    echo "Please enter a quantity.";
}

Upvotes: 1

Related Questions