Click here to Skip to main content
15,909,440 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i just want to insert item from admin section to table 'items' in my webshop..
i got message that is inserted,and got picture in folder but nothing in database...no erors so idk what is wrong..
my code is simple query ,

pics of my tables...atm i wanna insert into 'items'
[^] - PICTURE HERE
also do i need to do some joins or somethign? pls help me

What I have tried:

<?php

$conn = mysqli_connect('localhost','root','','webshop'); 


$cat=$_POST['cat'];
$subcat=$_POST['subcat'];
$name=$_POST['name'];
$brand=$_POST['brand'];
$img=$_FILES['file']['tmp_name'];
$img=$_FILES['fileone']['tmp_name'];
$price=$_POST['price'];
$desc=$_POST['description'];
 
if (isset($_POST["submit"])) 
 {	 
 mysqli_query($conn,"insert into items ( category, subcategory, name, brand, img, price, description ) values ('$cat', '$subcat', '$name', '$brand','$img','$price','$desc' )" );
	 {  
	    move_uploaded_file($_FILES['file']['tmp_name'],"../img_items/".$_FILES['file']['name']);
	    move_uploaded_file($_FILES['fileone']['tmp_name'],"../img_items/".$_FILES['fileone']['name']);
		echo "<font size='+2'>item inserted successfully</font>";
	    
		}
 }
else {

	echo "Sorry Something went wrong!!";
}
Posted
Updated 26-Jul-17 4:22am

1 solution

Your code does not check if the command was successful. Use something like
PHP
if (mysqli_query($conn,"insert into items ( category, subcategory, name, brand, img, price, description ) values ('$cat', '$subcat', '$name', '$brand','$img','$price','$desc' )" ) === TRUE)
{
    /* success */
}
else
{
    /* failure */
    printf("Insert failed: %s\n", mysqli_error($conn));
}
 
Share this answer
 
Comments
Sfjklm 26-Jul-17 11:22am    
TNX !!!! it's actually error reporting solve issue, i didn't put default value for 'sale' and i got it in tables...that was problem..now everything works as charm !!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900