-2

I'm able to see all the data that i have entered in form but not able to insert it into table.

<?php
echo "u r at starting";
$product_title = $_POST["product_title"];
$product_cat = $_POST["product_cat"];
$cat = $_POST["cat"];
$product_price = $_POST["product_price"];
$product_keywords = $_POST["product_keywords"];
$product_desc = $_POST["product_desc"];

$product_img1 = $_FILES["product_img1"]["name"];
$product_img2 = $_FILES["product_img2"]["name"];
$product_img3 = $_FILES["product_img3"]["name"];

echo $product_title;
echo $product_cat;
echo $cat;
echo $product_price;
echo $product_keywords;
echo $product_desc;
echo $product_img1;
echo $product_img2;
echo $product_img3;


if(isset($_POST["abc"]))
{

$temp_name1 = $_FILES["product_img1"]["tmp_name"];
$temp_name2 = $_FILES["product_img2"]["tmp_name"];
$temp_name3 = $_FILES["product_img3"]["tmp_name"];

move_uploaded_file($temp_name1, "product_images/img1");
move_uploaded_file($temp_name2, "product_images/img2");
move_uploaded_file($temp_name3, "product_images/img3");

$insert_product = "INSERT INTO product_tab VALUES('$product_cat','$cat_id',NOW(),'$product_title','$product_img1','$product_img2','$product_img3','$product_price','$product_keywords','$product_desc')";

$run_product = mysqli_query($con,$insert_product);
echo $run_product;
if($run_product)
{

    echo "Product inserted successfully";
}
else
{
    echo "NOt inserted";
}
}
echo "end";
?>
Emma
  • 27,428
  • 11
  • 44
  • 69
  • 1
    You don't know what's wrong because you don't check for errors in your code. Never assume the code is always going to work flawlessly. Use [`mysqli_error()`](http://php.net/manual/en/mysqli.error.php) to get a detailed error message from the database. – John Conde Jun 02 '19 at 19:33
  • 2
    Please read about **[SQL injection](https://en.wikipedia.org/wiki/SQL_injection)**. Instead of building queries with string concatenation, use **[prepared statements](https://secure.php.net/manual/en/pdo.prepare.php)** with **[bound parameters](https://secure.php.net/manual/en/pdostatement.bindparam.php)**. See **[this page](https://phptherightway.com/#databases)** and **[this post](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)** for some good examples. – John Conde Jun 02 '19 at 19:33
  • [How to enable MySQLi exception mode?](https://stackoverflow.com/questions/22662488/how-to-get-mysqli-error-information-in-different-environments/22662582#22662582) – Dharman Jun 02 '19 at 21:30
  • i tried that way making changes in my code. After that also not able to get any error echo message or any update in database. – Meet Yogi Jun 03 '19 at 11:46

1 Answers1

-1

Is $con a defined variable in the script? The code you have shown does not define $con.