【发布时间】:2015-05-12 20:09:05
【问题描述】:
所以,我有以下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
}
在获得$custInfo 后,我关闭了else if 所在的PHP 块,然后开始重新显示用户之前填写的html 表单。我在 HTML 中使用更多 PHP 块来填写表单,因为它是使用存储在 $custInfo 中的值创建的。然后我启动另一个 PHP 块并关闭 else if 文件继续。
在初始化$custInfo 后调用var_dump($custInfo) 会得到预期的结果:
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@email.com" ["address "]=> string(32) "第 1 行,第 2 行,城市,县。" ["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" ["橄榄"]=> 字符串(1) "Y" ["onions"]=> 字符串(1) "Y" ["createdatetime"]=> 字符串(19) "2015-05-11 13:40:08" }
但是,我得到以下输出:
这是范围问题还是我在这里做错了什么?如果需要,我可以提供更多代码或 JSFiddle。提前致谢!
【问题讨论】:
-
我在你的 var_dump 中看不到
$custInfo[10]的价值。你?$custInfo具有命名属性,未编号。 -
@JonathanM 我愿意。它包含
Y。 -
真的吗?在哪里?我看到
pineapples和pepperoni等的值为Y,但没有10。 -
@JonathanM 是的,在我发表评论后我明白了你的意思。我的错。