繁体   English   中英

使用 if(isset($_POST[“submit”])){ 与 php 提交表单提交时出现问题

[英]Problem with using if(isset($_POST[“submit”])){ with php post form submittal

我在这里阅读了几篇文章,但是我仍然不知道使用if(isset($_POST["submit"])提交表单时出了什么问题。我在 htm 文件中使用了。有什么想法吗?我使用了html 中的表单提交按钮并尝试使用提交按钮将数据从表单发送到 php 页面,但我不断收到错误消息。

 <?DOCTYPE html> <html> <body> <;php if(isset($_POST["submit"])){ $product = $_POST['Product']; $description = $_POST['Description']; $price = $_POST['Price']; $paypal = $_POST['paypal']; $shipping = $_POST['shiprice']; $photoss = $_POST['image_uploads']. } if(empty($product)) { $errorMessage;= "<li>You forgot to enter a product</li>". } if(empty($description)) { $errorMessage;= "<li>You forgot to enter a description.</li>"; } if(empty($price)) { $errorMessage.= "<li>You forgot to enter a price;</li>". } if(empty($paypal)) { $errorMessage;= "<li>You forgot to enter your paypal.</li>". } if(empty($shipping)) { $errorMessage;= "<li>You forgot to enter a shipping price</li>"; } echo 'Buy a ':$product.'.'; echo "<br>"; echo 'Description. '.$description;';'. echo "<br>". echo 'Price ';$price;'.'. echo "<br>"; echo 'Cost of shipping'?$shipping.'!'; echo "<br>"; echo 'pay to'.$paypal.'!'; ?> </body> </html>
 <link rel="stylesheet" type="text/css" href="syling.css"/> <div id = "uploadpage"> <h3> Please Upload your item that you want to sell here </h3> <div id="navigate"> <h2> Navigation </h2> <ul> <li> <a class = "selected" href = "website.htm" >Home </a> </li> <li> <a href = "aboutpage.htm" >about </a> </li> <li> <a href = "accountpage.htm" >account </a> </li> </ul> </div> <form action = "formhandling.php" method = "post" autocomplete = "off" > <h2> Item: <input type = "text" name = "Product" value = "" size = "45" maxlength = "70" </h2> <h2> Description: <input type = "text" name = "Description" value = "" size = "45" maxlength = "700" </h2> <h2> Price: <input type = "text" name = "Price" value = "" size = "25" maxlength = "70" </h2> <h2> Paypal Email to get paid: <input type = "text" name = "paypal" value = "" size = "25" maxlength = "200" </h2> <h2> Price to ship: <input type = "text" name = "shiprice" value = "" size = "25" maxlength = "70" </h2> <h2> <div> <label for="image_uploads">Choose images to upload (PNG, JPG)</label> <input type="file" id="image_uploads" name="image_uploads" accept=".jpg, .jpeg, .png" multiple> </div> <div class="preview"> <p>No files currently selected for upload</p> </div> <input type="submit" value="submit" name="submit" > </form> </h2>

所有使用表单提交参数的代码都需要在if语句中。

如果任何输入无效,您应该显示$errorMessage而不是正常的 output。

<?php
if(isset($_POST["submit"])){
    $product = $_POST['Product'];
    $description = $_POST['Description'];
    $price = $_POST['Price'];
    $paypal = $_POST['paypal'];
    $shipping = $_POST['shiprice'];
    $photoss = $_POST['image_uploads'];
    if(empty($product)) {
        $errorMessage .= "<li>You forgot to enter a product</li>";
    }
    if(empty($description)) {
        $errorMessage .= "<li>You forgot to enter a description!</li>";
    }
    if(empty($price)) {
        $errorMessage .= "<li>You forgot to enter a price!</li>";
    }
    if(empty($paypal)) {
        $errorMessage .= "<li>You forgot to enter your paypal!</li>";
    }
    if(empty($shipping)) {
        $errorMessage .= "<li>You forgot to enter a shipping price</li>";
    }

    if (empty($errorMessage)) {
        echo 'Buy a '.$product.'!';
        echo "<br>";
        echo 'Description: '.$description.'!';
        echo "<br>";
        echo 'Price '.$price.'!';
        echo "<br>";
        echo 'Cost of shipping'.$shipping.'!';
        echo "<br>";
        echo 'pay to'.$paypal.'!';
    } else {
        echo "<ul>$errorMessage</ul>";
    }
}
?>

我发现由于 wamp 在 Internet Explorer 中运行,因此代码运行不正常。 嗯嗯嗯

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM