产品未插入数据库中

时间:2017-08-17 07:19:43

标签: php html mysql

<?php

$servername = "localhost";
$username = "root";
$password = "";

// Create connection
$con = new mysqli($servername, $username, $password);

mysqli_select_db($con,'go');

if(isset($_POST['insert_post'])){
    $product_cat = $_POST['product_cat'];
    $product_brand = $_POST['product_brand'];
    $product_title = $_POST['product_title'];
    $product_price = $_POST['product_price'];
    $product_desc = $_POST['product_desc'];
    $product_keywords = $_POST['product_keywords'];
    $product_image = $_FILES['product_image']['name'];
    $product_image_tmp = $_FILES['product_image']['tmp_name'];
    if($product_title==''  OR $product_keywords==''){
        echo "<script> alert('please field all the fields!')</script>";
        exit();
    }
    else{
        $insert_query = "insert into 
     products(product_cat,product_brand,product_title,product_price,product_desc,product_keywords,product_image) values('$product_cat','$product_brand','$product_title','$product_price','$product_desc','$product_keywords','$product_image')";

        move_uploaded_file($product_image_tmp,"images/{$product_image}");
        if(mysqli_query($con,$insert_query)){
            echo "<script>alert('Data inserted into table')</script>";
        }
    }
}
?>

0 个答案:

没有答案