dousi4900 2016-06-07 09:01
浏览 36

表单提交的数据不会上传到数据库中

I am using phpcode to get data from form and upload it into database. But the data is not saved in database.Here 'insert_product.php' is the file where the entire code resides and form is redirected to same page after button is clicked. Anyone can help?

   <form action="insert_product.php" method="post" enctype="multipart/form-data">

        <table align="center" width="795" border="2" bgcolor="#187eae">

            <tr align="center">
                <td colspan="7"><h2>Insert New Post Here</h2></td>
            </tr>

            <tr>
                <td align="right"><b>Product Title:</b></td>
                <td><input type="text" name="product_title" size="60" required/></td>
            </tr>

            <tr>
                <td align="right"><b>Product Category:</b></td>
                <td>
                <select name="product_cat" >
                    <option>Select a Category</option>
                    <option value="1">Laptop</option>
                    <option value="2">Computer</option>
                </select>


                </td>
            </tr>

            <tr>
                <td align="right"><b>Product Brand:</b></td>
                <td>
                <select name="product_brand" >
                    <option>Select a Brand</option>
                    <option value="1">LG</option>
                    <option value="2">Samsung</option>
                </select>


                </td>
            </tr>

            <tr>
                <td align="right"><b>Product Image:</b></td>
                <td><input type="file" name="product_image" /></td>
            </tr>

            <tr>
                <td align="right"><b>Product Price:</b></td>
                <td><input type="text" name="product_price" required/></td>
            </tr>

            <tr>
                <td align="right"><b>Product Description:</b></td>
                <td><textarea name="product_desc" cols="20" rows="10"></textarea></td>
            </tr>

            <tr>
                <td align="right"><b>Product Keywords:</b></td>
                <td><input type="text" name="product_keywords" size="50" required/></td>
            </tr>

            <tr align="center">
                <td colspan="7"><input type="submit" name="insert_post" value="Insert Product Now"/></td>
            </tr>

        </table>


    </form>


</body>
</html>
<?php

    if(isset($_POST['insert_post'])){

        //getting the text data from the fields
        $product_title = $_POST['product_title'];
        $product_cat= $_POST['product_cat'];
        $product_brand = $_POST['product_brand'];
        $product_price = $_POST['product_price'];
        $product_desc = $_POST['product_desc'];
        $product_keywords = $_POST['product_keywords'];

        //getting the image from the field
        $product_image = $_FILES['product_image']['name'];
        $product_image_tmp = $_FILES['product_image']['tmp_name'];

        move_uploaded_file($product_image_tmp,"product_images/$product_image");

         $insert_product = "insert into products (product_cat,product_brand,product_title,product_price,product_desc,product_image,product_keywords) values ('$product_cat','$product_brand','$product_title','$product_price','$product_desc','$product_image','$product_keywords')";

         $insert_pro = mysqli_query($con, $insert_product);

         if($insert_pro){

         echo "<script>alert('Product Has been inserted!')</script>";
         echo "<script>window.open('index.php?insert_product','_self')</script>";

         }
    }








?>
  • 写回答

2条回答 默认 最新

  • dto52236 2016-06-07 09:07
    关注

    If this is the entire code, I can't find something like $con = mysqli_connect(...) Obviously you need to connect to the database before executing any queries on it

    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改