Trevor
Trevor

Reputation: 169

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">

I cannot understand why, in the following code, the else clause is never performed. The form is displayed, but when I press the Submit button nothing happens. Can anyone help? Cheers.

<!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

Upvotes: 0

Views: 2413

Answers (1)

mario.van.zadel
mario.van.zadel

Reputation: 2949

Please change

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

to

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

Upvotes: 1

Related Questions