$\u post不工作当我回音的时候

3okqufwl  于 2021-06-25  发布在  Mysql
关注(0)|答案(2)|浏览(209)

代码:

<!DOCTYPE html >
<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
 <script src="https://cloud.tinymce.com/stable/tinymce.min.js"></script>
  <script>tinymce.init({ selector:'textarea' });</script>
</head>

<body>

<form action="insert_product.php" method="post" enctype="multipart/form-data">
    <table>
            <tr>
                <td>Name</td>
                <td><input type="text" name="product_title" required="required"></td>

            </tr>

            <tr>
                <td>category</td>
                <td><select name="product_category" >
                <option>Select a Category</option>

                <?php

                     $get_cats = " select * from categories"; 
                     $run_cats = mysqli_query($con, $get_cats);

                     while($row_cats = mysqli_fetch_array($run_cats))
                     {
                            $cat_id = $row_cats['cat_id'];
                            $cat_title = $row_cats['cat_data']; 

                        echo "

                        <option>$cat_title </option>

                        ";
                        }
                ?>

                </select></td>

            </tr>

            <tr>
                <td>featured</td>
                <td><select name="product_featured" >
                <option>0</option>
                <option>1</option>
                </select></td>

            </tr>

            <tr>
                <td>price</td>
                <td><input type="text" name="product_price" required="required"></td>

            </tr>

            <tr>
                <td>image</td>
                <td><input type="file" name="product_image" required="required"></td>

            </tr>

            <tr>
                <td>keywords</td>
                <td><input type="text" name="product_keywords" required="required"></td>

            </tr>

            <tr>
                <td>description</td>
                <td><textarea name="product_description" cols="20" rows="10" ></textarea></td>

            </tr>

            <tr>
                <td><input type="submit" value="Add Product" name="insert_post"></td>
            </tr>

    </table>
</form>

</body>

</html>

<?php 
        if( isset($_POST['insert_post']))
        {

            $product_title = $_POST['$product_title'];
            $product_category = $_POST['$product_category'];
            $product_featured = $_POST['product_featured'];
            $product_price = $_POST['$product_price'];
            $product_keywords = $_POST['$product_keywords'];
            $product_description = $_POST['$product_description'];
            $product_image = $_FILES['product_image']['name'];
            $product_image_tmp = $_FILES['product_image']['tmp_name'];

        echo  $insert_product = " insert into products (product_cat, product_featured, product_title, product_price, product_desc,product_image,product_keywords) values ('$product_category','$product_featured','$product_title','$product_price','$product_description','$product_image','$product_keywords','$product_keywords')";
        }
 ?>

这是我打印代码时得到的结果 echo ```
insert into products (product_cat, product_featured, product_title, product_price, product_desc,product_image,product_keywords) values ('','1','','','','champagne culture logo men.png','','')

有人能告诉我我做错了什么吗?我反复检查,看看我是否有任何拼写错误或类似的性质,但我似乎不能确定到底是什么我做错了。如果您能提供任何帮助,我们将不胜感激
zazmityj

zazmityj1#

拆下 $ 关键部分:

$product_title = $_POST['$product_title'];
        $product_category = $_POST['$product_category'];
        $product_featured = $_POST['product_featured'];
        $product_price = $_POST['$product_price'];
        $product_keywords = $_POST['$product_keywords'];
        $product_description = $_POST['$product_description'];

应该是

$product_title = $_POST['product_title'];
        $product_category = $_POST['product_category'];
        $product_featured = $_POST['product_featured'];
        $product_price = $_POST['product_price'];
        $product_keywords = $_POST['product_keywords'];
        $product_description = $_POST['product_description'];
aij0ehis

aij0ehis2#

你需要改变这个

$product_title = $_POST['$product_title'];
$product_category = $_POST['$product_category'];
$product_featured = $_POST['product_featured'];
$product_price = $_POST['$product_price'];
$product_keywords = $_POST['$product_keywords'];
$product_description = $_POST['$product_description'];
$product_image = $_FILES['product_image']['name'];
$product_image_tmp = $_FILES['product_image']['tmp_name'];

为了这个

$product_title = $_POST['product_title'];
$product_category = $_POST['product_category'];
$product_featured = $_POST['product_featured'];
$product_price = $_POST['product_price'];
$product_keywords = $_POST['product_keywords'];
$product_description = $_POST['product_description'];
$product_image = $_FILES['product_image']['name'];
$product_image_tmp = $_FILES['product_image']['tmp_name'];

笔记
如果没有错误,则需要确保输入是否为空,可以使用empty()属性检查变量/输入是否为空。
喜欢

if(empty($_POST['product_title'])) {
    echo "product title shouldn't empty";
}

相关问题