PHP form - on submit stay on same page

后端 未结 9 802
醉梦人生
醉梦人生 2020-11-29 01:49

I have a PHP form that is located on file contact.html.

The form is processed from file processForm.php.

When a user fills out the

相关标签:
9条回答
  • 2020-11-29 02:13

    Friend. Use this way, There will be no "Undefined variable message" and it will work fine.

    <?php
        if(isset($_POST['SubmitButton'])){
            $price = $_POST["price"];
            $qty = $_POST["qty"];
            $message = $price*$qty;
        }
    
            ?>
    
        <!DOCTYPE html>
        <html>
        <head>
            <title></title>
        </head>
        <body>
            <form action="#" method="post">
                <input type="number" name="price"> <br>
                <input type="number" name="qty"><br>
                <input type="submit" name="SubmitButton">
            </form>
            <?php echo "The Answer is" .$message; ?>
    
        </body>
        </html>
    
    0 讨论(0)
  • 2020-11-29 02:14

    Try this... worked for me

    <form action="submit.php" method="post">
    <input type="text" name="input">
    <input type="submit">
    </form>
    

    ------ submit.php ------

    <?php header("Location: ../index.php"); ?>
    
    0 讨论(0)
  • 2020-11-29 02:18

    The best way to stay on the same page is to post to the same page:

    <form method="post" action="<?=$_SERVER['PHP_SELF'];?>">
    
    0 讨论(0)
提交回复
热议问题