【发布时间】:2014-02-06 07:14:09
【问题描述】:
我有以下 PHP 代码:
<?php
//Connection to PDO Database
?>
<form method="post" action="">
<p>Busisness telephone 1</p><input id="business_telephone_01" name="business_telephone_01" tabindex="auto" value="<?php echo $result['business_telephone_01']; ?>" type="text" />
<input name="submit" type="submit" value="Save Changes"></form>
<?php
//Get from Form
if((empty($_POST['submit']) === false)){
$business_telephone_01 = $_POST['business_telephone_01'];
//Formating of telephone numbers
$message = 'This message I want to display';
echo 'This is another message';
}
echo $message;
//Code to update table through PDO
?>
无论我在哪里回显,它是 echo 'This is another message'; 在条件括号内还是 _ echo $message;_ 在括号外没有回显,也没有错误正在显示。
html 表单和 PDO 工作正常并且正在更新,但没有任何响应。错误日志中没有显示错误。
更新:
- 如果我使用
if((empty($_POST['submit']) === false)){我会得到 PHP 注意:未定义变量:hello - 如果我使用
if (isset($_POST['submit'])) {我会收到 PHP 通知: 未定义变量:你好 - 如果我使用
if (!isset($_POST['submit'])) {,它会给我一个我使用的未定义变量的列表,例如从 我在business_telephone_01上面的代码
我的完整代码
if((empty($_POST['submit']) === false)){
//Get from Form
$address_building_name = $_POST['address_building_name'];
$address_building_number = $_POST['address_building_number'];
$address_street = $_POST['address_street'];
$address_locality = $_POST['address_locality'];
$address_postcode = $_POST['address_postcode'];
$address_country = $_POST['address_country'];
//Formating of address
$address_building_number = strtoupper($address_building_number);
$address_building_number = str_replace(' ','',$address_building_number);
$address_building_name = ucwords($address_building_name);
$address_street = ucwords($address_street);
$address_locality = ucwords($address_locality);
$address_postcode = strtoupper($address_postcode);
$address_country = ucwords($address_country);
echo 'Hello';
$good = 'Good bye';
}
echo $good;
【问题讨论】:
-
为什么不简单地使用 if($_POST['submit']){?另外,提交时有错误吗?
-
@dwhite.me '因为如果
$_POST['submit']不存在,它会发出警告。 -
不一定,您可以关闭这些消息。那么你应该使用 isset($_POST['submit']) 。
-
当我写这篇文章的时候,@leng 的回答完全符合我的意思。