<form action =“&lt;?= $ _ SERVER [&#39; PHP_SELF&#39;]?&gt;”方法= “POST”>

时间:2015-08-21 08:36:50

标签: php mysql post

我无法理解为什么在以下代码中,从不执行else子句。显示表单,但是当我按下“提交”按钮时没有任何反应。有人可以帮忙吗?欢呼声。

<!doctype html>
<html>
<head>
    <meta charset = "utf-8">
    <title>Listing 12-3</title>
</head>

<body>
<h1>Query the Shop Database</h1>
<h3>Search for a Product</h3>
<p> Use a wildcard if necessary - % in front / behind text</p>
<?php
    tryagain:
    // Wait for submit
    if (!$_POST['submit']) {
?>
    <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
        <p> Product Name: <input type ="text" name="product" /></p>
        <p><input type="submit" name = "submit" value = "Submit" /></p>
    </form>
<?php

        }
        else {
            // Connect to the Shop database

1 个答案:

答案 0 :(得分:1)

请更改

if (!$_POST['submit']) {

if (!isset($_POST['submit'])) {