Errors: "Notice: Undefined index" [duplicate] - php

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 5 years ago.
[Errors][1]
I posted the code that I edited, and there are new errors w/c i didn't understand
Notice: Undefined index: product_brand in
C:\xampp\htdocs\JGMarketing\Admin_Area\insert_product.php on line 152
Notice: Undefined index: product_price in
C:\xampp\htdocs\JGMarketing\Admin_Area\insert_product.php on line 153
Notice: Undefined index: product_images in
C:\xampp\htdocs\JGMarketing\Admin_Area\insert_product.php on line 158
Notice: Undefined index: product_images in
C:\xampp\htdocs\JGMarketing\Admin_Area\insert_product.php on line 159
<!DOCTYPE>
<?php
include("includes/db.php");
?>
<html>
<head>
<title>Inserting Product</title>
<script src="https://cloud.tinymce.com/stable/tinymce.min.js"></script>
<script>tinymce.init({ selector:'textarea' });</script>
</head>
<body bgcolor="red">
<form action="insert_product.php"method="post"enctype=
"multipart/form/data">
<table align="center" width="700" border="5" bgcolor="white" >
<tr>
<td colspan="8"><h2 style="text-align:center;font-family:Arial;">
Insert New Post Here</h2></td>
</tr>
<tr>
<td align="right"><b>Product Name:</b></td>
<td><input type="text" name= "product_name" size="60" required />
</td>
</tr>
<tr>
<td align="right"><b>Product Category:</b></td>
<td>
<select name="product_cat" required>
<option>Select Category</option>
<?php
global $con;
$get_cat = "select * from categories";
$run_cat = mysqli_query($con, $get_cat);
while ($row_cat=mysqli_fetch_array($run_cat)){
$cat_id= $row_cat['cat_id'];
$cat_title= $row_cat['cat_title'];
echo "<li><option>$cat_title</option></li>";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right"><b>Product Brand:</b></td>
<td>
<select name="product_brand" required>
<option>Select Brand</option>
<?php
global $con;
$get_brands = "select * from brands";
$run_brands = mysqli_query($con, $get_brands);
while ($row_brands=mysqli_fetch_array($run_brands)){
$brands_id= $row_brands['brand_id'];
$brands_title= $row_brands['brand_title'];
echo "<li><option>$brands_title</option></li>";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right"><b>Product Image:</b></td>
<td><input type="file" name= "product_image" required /></td>
</tr>
<tr>
<td align="right"><b>Product Price:</b></td>
<td><input type="currency" 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 Here"/></td>
</tr>
</table>
</body>
</html>
<?php
if(isset($_POST['insert_post'])){
//getting text data
$product_name = $_POST['product_name'];
$product_cat = $_POST['product_cat'];
$product_brands = $_POST['product_brand'];
$product_price = $_POST['product_price'];
$product_desc = $_POST['product_desc'];
$product_keywords = $_POST['product_keywords'];
//getting image data
$product_image = $_FILES['product_images']['name'];
$product_image_tmp = $_FILES['product_images']['tmp_name'];
move_uploaded_file($product_image_tmp,"products_images/$product_image");
$insert_product = "insert into products
(product_cat,product_brands,product_name,product_price,product_desc,
product_img,product_keyword) values ('$product_cat','$product_brands'
,'$product_name','$product_price','$product_desc','$product_image'
,'$product_keywords')";
$run_product = mysqli_query($con,$insert_product);
if($run_product){
echo"<script>alert('Product Has been inserted')</script>";
echo"<script>window.open('insert_product.php','_self')</script>";
}
}
?>

You define your submit button name as "insert_post". But in if condition you take another name (if(isset($_POST['insert_product']))). Change the name.

try use like this...please make sure check your db connection and form action properly.
if(isset($_POST['insert_post'])){
//getting text data from fields
$product_name = $_POST['product_name'];
$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 image from fields
$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_name,product_price,product_desc,product_image,product_keywords) values('$product_cat','$product_brand','$product_name','$product_price','$product_desc','$product_image','$product_keywords')";
$insert_pro = mysqli_query($con, $insert_product);
if($insert_pro){
echo"alert('Product Has been inserted')";
echo"window.open('insert_product.php','_self')";
}
else{
echo "Something has gone wrong";
}
}

Your Query IS wrong:
$insert_product="insert into products
(product_cat,product_brand,product_name,product_price,product_desc,product_image,product_keywords) values('$product_cat','$product_brand','$product_name','$product_price',','$product_desc','$product_image','$product_keywords')";
Insert This Query:
$insert_product="insert into products
(product_cat,product_brand,product_name,product_price,product_desc,product_image,product_keywords) values('$product_cat','$product_brand','$product_name','$product_price','$product_desc','$product_image','$product_keywords')";

Related

object of class mysqli _connect could not be converted to string in line 135

when i run the code it give error of object of class mysqli_connect could not be converted to string in line 135. please some one provide me the solution of this problem.
i tried searching for solution but no one worked for me. bellow is the code showing error.
$row = mysqli_connect("$con,$insert_product");
accepted to run but showing error in line 135. what mistake do i have make.full code is here
<?php require_once ("includes/db.php");
?>
<!DOCTYPE html>
<html>
<head>
<title> product</title>
</head>
<body>
<form method="post" action="insert_product.php" enctype="multipart/form-data">
<table width="700" align="center">
<tr>
<td><h2>insert new product</h2></td>
</tr>
<tr>
<td>Product title</td>
<td><input type="text" name="product_title"></td>
</tr>
<tr>
<td>Product category</td>
<td><select name="product_cat">
<option>Select a category</option>
<?php
$get_cats = "select * from category";
$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_title'];
echo "<option value='$cat_id'>$cat_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>Product brand</td>
<td><select name="product_brand">
<option>Select brand</option>
<?php
$get_brand = "select * from brand";
$run_brand= mysqli_query($con,$get_cats);
while ($row_brand=mysqli_fetch_array($run_brand))
{
$brand_id = $row_brand['brand_id'];
$brand_title=$row_brand['brand_title'];
echo "<option value='$cat_id'>$cat_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>product image1</td>
<td><input type="file" name="product_img1"></td>
</tr>
<tr>
<td>Product image2</td>
<td><input type="file" name="product_img2"></td>
</tr>
<tr>
<td>Product image3</td>
<td><input type="file" name="product_img3"></td>
</tr>
<
<tr>
<td>Product price</td>
<td><input type="number" name="product_price"></td>
</tr>
<tr>
<td>Product desceptration</td>
<td><input type="text" name="product_desc"></td>
</tr>
<tr>
<td>Product keyword</td>
<td><input type="number" name="product_keyword"></td>
</tr>
<tr>
<td><input type="submit" value="submit" name="submit"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$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'];
$status='on';
$product_keyword=$_POST['product_keyword'];
//image name
$product_img1 = $_FILES['product_img1']['name'];
$product_img2 = $_FILES['product_img2']['name'];
$product_img3 = $_FILES['product_img3']['name'];
//image temp names
$temp_name1 = $_FILES['product_img1']['tmp_name'];
$temp_name2 = $_FILES['product_img2']['tmp_name'];
$temp_name3 = $_FILES['product_img3']['tmp_name'];
if($product_title=='' OR $product_cat=='' OR $product_brand=='' OR $product_price=='' OR $product_desc=='' OR $product_keyword=='' OR $product_img1=='' OR $product_img2=='' OR $product_img3=='')
{
echo "<script> alert ('please insert the data in the form')</script>";
exit();
}
else{
//uploadinimage to the folder
move_uploaded_file($temp_name1,"product_images/$product_img1");
move_uploaded_file($temp_name2, "product_images/$product_img2");
move_uploaded_file($temp_name3,"product_images/$product_img3");
}
$insert_product = "insert into products (cat_id,brand_id,date,product_title,product_img1,product_img2,product_img3,product_brand,product_price,product_desc,status) values ('$product_cat','$product_brand',NOW(),'$product_title','$product_img1','$product_img2',$product_img3,'product_brand','product_price','product_desc','product_keyword')";
$row = mysqli_connect("$con,$insert_product");
if($row)
{
echo "<script> alert('insert sucessfully')</script>";
}
else
{
echo "<script> alert(' unsucessfull to insert')</script>";
}
}
?>
I don't think you're meaning to connect again. Rather, it appears you may be trying to perform a query?
Your code:
$insert_product = "insert into products (cat_id,brand_id,date,product_title,product_img1,product_img2,product_img3,product_brand,product_price,product_desc,status) values ('$product_cat','$product_brand',NOW(),'$product_title','$product_img1','$product_img2',$product_img3,'product_brand','product_price','product_desc','product_keyword')";
$row = mysqli_connect("$con,$insert_product");
Not only are you referencing a variable never defined in the script (though it probably is in the file you require at the top), but you're passing a query right to mysqli_connect(). I imagine what you actually meant to do is:
$insert_product = "insert into products (cat_id,brand_id,date,product_title,product_img1,product_img2,product_img3,product_brand,product_price,product_desc,status) values ('$product_cat','$product_brand',NOW(),'$product_title','$product_img1','$product_img2',$product_img3,'product_brand','product_price','product_desc','product_keyword')";
$row = mysqli_query($con, $insert_product);

$_POST not working. when I echo it

Code:
<!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')";
}
?>
this is the result I get from this code when I print it with 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','','')
can someone please tell me what I'm doing wrong? I've checked repeatedly checked to see if i had any spelling errors or anything of that nature but I cant seem to identify exactly what it is that I am doing wrong. Any help you could provide would be greatly appreciated
Remove the $ part from the key:
$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'];
Should be
$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'];
You need to change this
$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'];
to this
$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'];
NOTE
if there was no error, you need to make sure if the input is not empty, you can use empty() property to check if the variable/input is empty.
like
if(empty($_POST['product_title'])) {
echo "product title shouldn't empty";
}

MySQL database not updating when form is submited

EDITED I am using HTML forms and PHP to upload data to a MySQL database. When I submit the information an image that i uploaded gets moved to a specific folder(the way i intended it to), but the data does not get uploaded to the data base.
I added most of the code now, the site didn't allow me to add everything, I deleted some lines that in my opinion don't have anything to do with the problem at hand. so maybe you'll see the problem:
<!DOCTYPE>
<?php
include("includes/db.php");
?>
<html>
<head>
<title>Inserting Product</title>
<script src="//tinymce.cachefly.net/4.1/tinymce.min.js"></script>
<script>
tinymce.init({selector:'textarea'});
</script>
</head>
<body bgcolor="grey">
<form action="insert_product.php" method="post" enctype="multipart/form-
data">
<table align="center" width="795" border="2" bgcolor="lime">
</tr>
<tr>
<td align="right"><b>Product Category:</b></td>
<td>
<select name="product_cat" >
<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_title'];
echo "<option value='$cat_id'>$cat_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right"><b>Product Publisher:</b></td>
<td> <select name="product_dev">
<option>Select a Publisher</option>
<?php
$get_devs = "select * from developers";
$run_devs = mysqli_query($con, $get_devs);
while ($row_devs=mysqli_fetch_array($run_devs)){
$dev_id = $row_devs['dev_id'];
$dev_title = $row_devs['dev_title'];
echo "<option value='$dev_id'>$dev_title</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 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'])){
$product_title = $_POST['product_title'];
$product_cat= $_POST['product_cat'];
$product_pub = $_POST['product_pub'];
$product_dev = $_POST['product_dev'];
$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'];
move_uploaded_file($product_image_tmp,"product_images/$product_image");
$insert_product = "insert into products
(product_cat,product_pub,product_dev,
product_title,product_price,product_desc,product_image,
product_keywords) values ('$product_cat','$product_pub','$product_dev',
'$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>";
}
}
?>
Your query seems fine.
Just verify your MySQLi connection.
It should be like:
$con = mysqli_connect("HOST", "USERNAME", "PASSWORD", "DATABASE_NAME");

when i upload file to phpmyadmin show error in 4 lines

I create this upload form for uploading products to phpmyadmin but when I click on upload button its error in 4 lines:
Notice: Undefined index: file in C:\xampp\htdocs\MyShop\admin_area\insert_product.php on line 102
Notice: Undefined index: file in C:\xampp\htdocs\MyShop\admin_area\insert_product.php on line 103
Notice: Undefined index: file in C:\xampp\htdocs\MyShop\admin_area\insert_product.php on line 104
Notice: Undefined index: file in C:\xampp\htdocs\MyShop\admin_area\insert_product.php on line 105
My html is:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>
Untitled Document
</title>
</head>
<body>
<form action="insert_product.php" method="post" encypt="multipart/form-data">
<table align="center" width="800" >
<tr>
<td>
Insert New Post
</td>
</tr>
<tr>
<td>
<b>
Product title:
</b>
</td>
<td>
<input type="text" name="product_title" required/>
</td>
</tr>
<tr>
<td>
<b>
Product Category:
</b>
</td>
<td>
<select name="product_cat">
<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_title'];
echo "<option value='$cat_id'>$cat_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right">
<b>
Product Image
</b>
</td>
<td>
<input type="file" name="file" />
</td>
</tr>
<tr>
<td>
<b>
Product Price:
</b>
</td>
<td>
<input type="text" name="product_price" />
</td>
</tr>
<tr>
<td>
<b>
Product Description:
</b>
</td>
<td>
<textarea name="product_desc"></textarea>
</td>
</tr>
<tr>
<td>
<b>
Product keywords:
</b>
</td>
<td>
<input type="text" name="product_keywords" />
</td>
</tr>
<tr>
<td>
<input type="submit" name="insert_post" value="Insert Product" />
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['insert_post'])) {
$product_title = $_POST['product_title'];
$product_cat = $_POST['product_cat'];
$product_price = $_POST['product_price'];
$product_desc = $_POST['product_desc'];
$product_keywords = $_POST['product_keywords'];
$file = rand(1000,100000)."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$folder="uploads/";
// new file size in KB
$new_size = $file_size/1024;
$new_file_name = strtolower($file);
// make file name in lower case
$final_file=str_replace(' ','-',$new_file_name);
// new file size in KB
move_uploaded_file($file_loc,$folder.$final_file);
$insert_product = "insert into products (product_cat,product_title,file,type,size,,product_price,product_desc,product_keywords) values ('$product_cat','$product_title','$final_file','$file_type','$new_size','$product_price','$product_desc','$product_keywords')";
$insert_pro = mysqli_query($con, $insert_product);
if($insert_pro) {
echo "<script>alert('Product has been inserted!')</script>";
echo "<script>window.open('insert_product.php','_self')</script>>";
}
}
?>
You need to check isset condition before taking action on $_FILES
if(isset($_FILES['file']['name']))
{
$file = rand(1000,100000)."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$folder="uploads/";
// new file size in KB
$new_size = $file_size/1024;
$new_file_name = strtolower($file);
// make file name in lower case
$final_file=str_replace(' ','-',$new_file_name);
// new file size in KB
move_uploaded_file($file_loc,$folder.$final_file);
}
You have typo error in form enctype:
<form action="insert_product.php" method="post" enctype="multipart/form-data">

Receiving empty form values using php and post [duplicate]

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 6 years ago.
I am making a insertion form to add a product to the mysql database. I am using echo command to print the query. The printed query is showing empty values like this:
Notice: Undefined index: product_cat in F:\Apache24\htdocs\Site1\admin\product_add.php on line 40
Notice: Undefined index: product_brand in
F:\Apache24\htdocs\Site1\admin\product_add.php on line 41
Notice: Undefined index: product_title in
F:\Apache24\htdocs\Site1\admin\product_add.php on line 42
Notice: Undefined index: product_price in
F:\Apache24\htdocs\Site1\admin\product_add.php on line 43
Notice: Undefined index: product_description in
F:\Apache24\htdocs\Site1\admin\product_add.php on line 44
Notice: Undefined index: product_keywords in
F:\Apache24\htdocs\Site1\admin\product_add.php on line 45
Notice: Undefined index: product_images in
F:\Apache24\htdocs\Site1\admin\product_add.php on line 48
Notice: Undefined index: product_images in
F:\Apache24\htdocs\Site1\admin\product_add.php on line 49
insert into products ('product_cat', 'product_brand', 'product_title',
'product_price', 'product_desc', 'product_image', 'product_keywords')
values( '', '', '', '', '', '', '')
This is the html form. It is also the action page:
<!DOCTYPE html>
<html>
<head>
<title>Admin Panel - Add Products</title>
<link rel="stylesheet" type="text/css" href="../styles/admin-style.css">
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<script>tinymce.init({ selector:'textarea' });</script>
<?php
include("../includes/connect.php");
function getcats_add_products(){
global $con;
$get_cats="select * from categories";
$run_cats=mysqli_query($con, $get_cats);
echo "<option>Select Category</option>";
while($row_cats = mysqli_fetch_array($run_cats)){
$cat_id = $row_cats['cat_id'];
$cat_title = $row_cats['cat_title'];
echo "<option value='$cat_id'>$cat_title</option>";
}
}
function getbrands_add_products(){
global $con;
$get_brands="select * from brands";
$run_brands=mysqli_query($con, $get_brands);
echo "<option>Select Brand</option>";
while($row_brands = mysqli_fetch_array($run_brands)){
$brand_id = $row_brands['brand_id'];
$brand_title = $row_brands['brand_title'];
echo "<option value='$brand_id'>$brand_title</option>";
}
}
if(isset($_POST['submit'])){
$product_cat = $_POST['product_cat'];
$product_brand = $_POST['product_brand'];
$product_title = $_POST['product_title'];
$product_price = $_POST['product_price'];
$product_desc = $_POST['product_description'];
$product_keywords = $_POST['product_keywords'];
$product_images = $_FILES['product_images']['name'];
$product_images_temp = $_FILES['product_images']['tmp_name'];
$product_query = "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_images',
'$product_keywords') ";
echo $product_query;
}
?>
</head>
<body>
<div class="wrapper">
<header>
</header>
<div class="heading">Add New Product</div>
<div class="product-table-div">
<form method="POST" action="" enctype="multipart/form-data">
<table class="product-table" border="1">
<tr>
<td id="product-add-label">Product Category</td>
<td>
<select id="product-table-input" name="product-cat">
<?php getcats_add_products(); ?>
</select>
</td>
</tr>
<tr>
<td id="product-add-label">Product Brand</td>
<td>
<select id="product-table-input" name="product-brand">
<?php getbrands_add_products(); ?>
</select>
</td>
</tr>
<tr>
<td id="product-add-label">Product title</td>
<td>
<input type="text" name="product-title" id="product-table-input">
</td>
</tr>
<tr>
<td id="product-add-label">Product Price</td>
<td>
<input type="number" name="product-price" id="product-table-input">
</td>
</tr>
<tr>
<td id="product-add-label">Product description</td>
<td>
<textarea rows="10" cols="30" name="product-description"></textarea>
</td>
</tr>
<tr>
<td id="product-add-label">Product image</td>
<td>
<input type="file" name="product-images" id="product-table-input">
</td>
</tr>
<tr>
<td id="product-add-label">Product Keywords</td>
<td>
<input type="text" name="product-keywords" id="product-table-input">
</td>
</tr>
<tr>
<td colspan="2">
<div id="product-submit-div">
<input type="reset" name="submitreset" id="product-submit" value="Clear">
<input type="submit" name="submit" id="product-submit" value="Add">
</div>
</td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
This location of this page is root>admin>product_add.php. What seems to be the problem?
Oh, I have also used tinymce text editor in the textarea.
You are using Hyphen - signs in the HTML form for the field names; but when you try to read in PHP, you are using underscores.
$product_cat = $_POST['product_cat'];
$product_brand = $_POST['product_brand'];
$product_title = $_POST['product_title'];
$product_price = $_POST['product_price'];
$product_desc = $_POST['product_description'];
$product_keywords = $_POST['product_keywords'];
Use below code instead of above
$product_cat = $_POST['product-cat'];
$product_brand = $_POST['product-brand'];
$product_title = $_POST['product-title'];
$product_price = $_POST['product-price'];
$product_desc = $_POST['product-description'];
$product_keywords = $_POST['product-keywords'];

Categories