【发布时间】:2015-03-14 22:07:49
【问题描述】:
我有下面的 html 表单并将其提交到 php 文件 (workcard_done.php)。我的问题是当我提交代码时它会回显 else echo "nothing here"; 如果我在 isset 上设置 not (!) 运算符,我会得到想要的结果吗?它应该适用于if(isset($_POST['submit']) && !empty($_POST['submit']))。
谁能告诉我下面的代码有什么问题让我发疯。
<!DOCTYPE html>
<HTML>
<head>
<title>yoyo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<form action="workcard_done.php" name="workCard_open" method="POST">
<br>
<table>
<tr>
<th>title 1</th>
<th>title 2</th>
</tr>
<tr>
<td><input type="text" name="name[]" value="" ></td>
<td><input type="text" name="price[]" value="" class="matr_price"/></td>
</tr>
<tr>
<td><input type="text" name="name[]" value="" ></td>
<td><input type="text" name="price[]" value="" class="matr_price"/></td>
</tr>
<tr>
<td>Total incl. VAT:</td>
<td><span type="text" name"sum[]" id="sum">0</span></td>
</tr>
</table>
<input type="submit" name"submit" class="submit" value="Done"/>
</form>
</body>
</html>
workcard_done.php
<!DOCTYPE html>
<html>
<head>
<title>title...</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<pre>
<?php
error_reporting(E_ALL);
if(isset($_POST['submit']) && !empty($_POST['submit'])) {
$name = $_POST['name'];
$price = $_POST['price'];
$user = $_POST['user'];
print_r($name);
echo "<br>";
print_r($price);
echo "<br>";
print_r($user);
echo "<br>";
}
else {
echo "nothing here";
}
?>
</pre>
</body>
</html>
如果在 isset 上设置 not (!) 运算符,我会得到以下想要的结果。
Array
(
[0] => slange
[1] => rfd
)
Array
(
[0] => 123
[1] => 200
)
Array
(
[user] => 2
)
【问题讨论】:
-
! isset($_POST['submit']) && ! empty($_POST['submit'])始终计算为FALSE。如果$_POST['submit']未设置,则它为空,! empty()计算结果为FALSE。如果已设置,则! isset()评估为 FALSE。每种方式的完整表达式都是FALSE。
标签: php arrays forms post isset