Reputation: 486
So, I have the following else if
:
else if (isset($_POST['orderID'])) {
/* Update order. */
$orderID = $_POST['orderID'];
$link = getConn();
$custInfo = getCustData($orderID, $link, $tableName);
//$custInfo contains [id, order_id, student, firstname, lastname, email, address, phone, price, size, anchovies,
//pepperoni, peppers, olives, onions, createdatetime]
?>
<form id='updateOrder' name='orderID' method='post' action='vieworder.php'>
<h3>What Size of Pizza Would You Like?</h3>
Small <input id='small' type='radio' name='pizzaSize' value='small' <?php echo ($custInfo[9]=='small')?'checked':''?>/>
Medium <input id='medium' type='radio' name='pizzaSize' value='medium' <?php echo ($custInfo[9]=='medium')?'checked':''?>/>
Large <input id='large' type='radio' name='pizzaSize' value='large' <?php echo ($custInfo[9]=='large')?'checked':''?>/>
<br>
<h3>Add Extra Toppings</h3>
Anchovies <input id='anchovies' type='checkbox' name='anchovies' value='yes' <?php echo ($custInfo[10]=='Y')?'checked':''?>/>
<br>
Pineapples <input id='pineapples' type='checkbox' name='pineapples' value='yes'<?php echo ($custInfo[10]=='Y')?'checked':''?>/>
<br>
Pepperoni <input id='pepperoni' type='checkbox' name='pepperoni' value='yes'<?php echo ($custInfo[10]=='Y')?'checked':''?>/>
<br>
Olives <input id='olives' type='checkbox' name='olives' value='yes' <?php echo ($custInfo[10]=='Y')?'checked':''?>/>
<br>
Onions <input id='onions' type='checkbox' name='onions' value='yes' <?php echo ($custInfo[10]=='Y')?'checked':''?>/>
<br>
Peppers <input id='peppers' type='checkbox' name='peppers' value='yes' <?php echo ($custInfo[10]=='Y')?'checked':''?>/>
<br>
<h3>Enter your details:</h3>
First Name: <input id='forename' type='text' name='forename' value="<?php echo htmlentities($custInfo[3]); ?>" required/>
<br>
Surname: <input id='surname' type='text' name='surname' value="<?php echo htmlentities($custInfo[4]); ?>" required/>
<br>
Address: <textarea id='address' name='address' rows='5' cols='30' value="<?php echo htmlentities($custInfo[6]); ?>" required></textarea>
<br>
Email Address: <input id='email' type='email' name='email' value="<?php echo htmlentities($custInfo[5]); ?>" required/>
<br>
Phone Number: <input id='phoneNumber' type='text' name='phone' value="<?php echo htmlentities($custInfo[7]); ?>" required/>
<br>
Tick here if you are a student: <input id='studentDiscount' type='checkbox' name='student'<?php echo ($custInfo[2]=='Y')?'checked':''?>/>
<br>
<button type='submit' value='Place Order'>Submit Order</button>
</form>
<?php
}
I close the PHP block where the else if
is began in after getting $custInfo
and then begin to redisplay a html form that the user had filled in earlier. I use more PHP blocks inside the HTML to fill in the form as it is created with the values stored in $custInfo
. I then start another PHP block and close the else if and the file continues.
Calling var_dump($custInfo)
after initialising $custInfo
gives an expected result:
array(17) { ["id"]=> string(3) "193" ["order_id"]=> string(13) "5550a328ddb36" ["student"]=> string(1) "Y" ["firstname"]=> string(6) "Peadar" ["lastname"]=> string(11) "Ó Duinnín" ["email"]=> string(15) "[email protected]" ["address"]=> string(32) "Line 1, Line 2, City, County." ["phone"]=> string(10) "0870123456" ["price"]=> string(5) "15.00" ["size"]=> string(5) "large" ["anchovies"]=> string(1) "Y" ["pineapples"]=> string(1) "N" ["pepperoni"]=> string(1) "N" ["peppers"]=> string(1) "Y" ["olives"]=> string(1) "Y" ["onions"]=> string(1) "Y" ["createdatetime"]=> string(19) "2015-05-11 13:40:08" }
However, I get the following output:
Is this a scope issue or am I doing something else wrong here? I can provide more code or a JSFiddle if requested. Thanks in advance!
Upvotes: 0
Views: 58
Reputation: 386
Since your array $custInfo
is an associative array the numerical offset won't be available. Instead of 9
or 10
you need to use the associated key that you assigned to it.
Upvotes: 1