can anyone help me where is the mistake?

A

Anonymous

Guest
Code:
</div>
							<div>
							
							<div id="form>">
							<form action="add_pro.php"method="post" enctype="multipart/form-data">
							<table align = "center" width= "80%" border="1" bgcolor="pink" cellpadding="8">
							<tr align="center">
							<td colspan="7"><h1>Add product</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" required/>
								<option>select A catogory</option>
								
								<?php

									$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 "<option value='$cat_id'>$cat_title</option>";
									}
									
								?>
								</select>
							</td>
							</tr>
							
							<tr>
							<td align="right"><b>Product Brand:</B></td>
							<td> <select name="product_brand" / >
							<option>Select Any Brand</option>
							<?php
							$get_brand ="SELECT * FROM `brands`";
	
							$run_brand = mysqli_query($con, $get_brand);
	
							while ($row_brand=mysqli_fetch_array($run_brand)){
		
							$brand_id = $row_brand['brand_id'];
							
							$brand_title =$row_brand['brand_title'];
		
							echo "<option value='brand_id'>$brand_title</option>";
							}
							?>
							</tr>
							
							<tr>
							<td align="right"><b>Product Image:</B></td>
							<td> <Input type="file" name="product_image" size= "60"required/> </td>
							</tr>
							
							<tr>
							<td align="right"><b>Product Price (Inr):</B></td>
							<td> <Input type="text" name="product_price" size= "60"/> </td>
							</tr>
							
							<tr>
							<td align="right"><b>Product Descriptions:</B></td>
							<td> <textarea name="product_desc"cols="20" rows="10" /> </textarea> </td>
							</tr>
							
							<tr>
							<td align="right"><b>Product Keyword:</B></td>
							<td> <Input type="text" name="product_keywords"/> </td>
							</tr>
							
							<tr><td align="center" colspan="7">
							<input type="submit" name ="insert_post" value= "add now"/></td>
	
				<?php
				if(isset($_post['insert_post'])){
					
					//getting the text details of 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
					$product_image = $_files['product_image']['name'];
					
					$product_image_tmp = $_files ['[product_image']['tmp_name'];
					
					move_uploaded_file($product_image_tmp,"product_images/$product_image");
					
		echo $add_pro = "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_keywords','$product_image',)";

$add_pro = mysqli_query($con, $add_product);

if ($add_pro){
	
echo "<script>alert ('done')</script>";

				
				}
				
				}
				
				?>
:help: :help:
 
I see this:

Code:
<select name="product_brand" / >

Which should be:

Code:
<select name="product_brand">

Are you getting any error messages?
 
Also this:

Code:
$product_image_tmp = $_files ['[product_image']['tmp_name'];

Should be:

Code:
$product_image_tmp = $_files ['product_image']['tmp_name'];

In this snippet of code you provided, neither the table or form tags are closed.
 
iam not getting any error message .
when i click the addnow button the page get refresed but there is no uary parse on my phpadmin or image folder.

i have successfully enabled all $con to my database i can read all table using same method but i could not post the quary?
 
Have you fixed the mistakes I noted?

You should put your PHP code above the HTML code also.
 
Yes i have tried that but still the same problem

iam using xxamp
and having database table name : products
with rows

(product_cat,product_brand,product_title,product_price,product_desc,product_image,product_keywords

i am able to Get the data in table but not POST.
Code:
<!DOCTYPE html>
<?php
include ("db.php");
?>
<html>
<head>

<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
  <script>tinymce.init({ selector:'textarea' });</script>
					<title>insert_product</title>
						</head>
					
		<body>				
						
						
							
							<form action="insert_product.php" method="post" enctype="multipart/form-data">
							<table align = "center" width= "80%" border="1" bgcolor="pink" cellpadding="8">
							<tr align="center">
							<td colspan="7"><h1>Add product</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" required/>
								<option>select A catogory</option>
								
								<?php

									$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 "<option value='$cat_id'>$cat_title</option>";
									}
									
								?>
								</select>
							</td>
							</tr>
							
							<tr>
							<td align="right"><b>Product Brand:</B></td>
							<td> <select name="product_brand" / >
							<option>Select Any Brand</option>
							<?php
							$get_brand ="SELECT * FROM `brands`";
	
							$run_brand = mysqli_query($con, $get_brand);
	
							while ($row_brand=mysqli_fetch_array($run_brand)){
		
							$brand_id = $row_brand['brand_id'];
							
							$brand_title =$row_brand['brand_title'];
		
							echo "<option value='brand_id'>$brand_title</option>";
							}
							?>
							</tr>
							
							<tr>
							<td align="right"><b>Product Image:</B></td>
							<td> <Input type="file" name="product_image" size= "60"required/> </td>
							</tr>
							
							<tr>
							<td align="right"><b>Product Price (Inr):</B></td>
							<td> <Input type="text" name="product_price" size= "60"/> </td>
							</tr>
							
							<tr>
							<td align="right"><b>Product Descriptions:</B></td>
							<td> <textarea name="product_desc"cols="20" rows="10" /> </textarea> </td>
							</tr>
							
							<tr>
							<td align="right"><b>Product Keyword:</B></td>
							<td> <Input type="text" name="product_keywords"/> </td>
							</tr>
							
							<tr align="center">
							<td colspan= "7"><input type= "submit" name ="insert_post" value= "insert product now"/></td>
	</form>
	
				
<?php
				if(isset($_post['insert_post'])){
					//getting the text details of 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
					$product_image = $_files['product_image']['name'];
					$product_image_tmp = $_files['[product_image']['tmp_name'];
					
move_uploaded_file($product_image_tmp,"product_images/$product.image");

echo $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_keywords','$product_image')";

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

if (isset($_POST['insert_post']))
	
echo "<script>alert('done')</script>";
echo "<script>window.open('add_pro.php','_self')</script>";

				
				}
				
				?>
			</body>
	</html>
 
sorry its old code


here is the new code as you told

Code:
<!DOCTYPE html>

<?php
$con = mysqli_connect("localhost","root","","myekarts");
// Check connection
if ($con->connect_error) {
    die("Connection failed: " . $con->connect_error);
} 
?>
<html>
<head>
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
  <script>tinymce.init({ selector:'textarea' });</script>
					<title>insert_product</title>
						</head>
					
		<body>				
						
						
							
							<form action="insert_product.php" method="post" enctype="multipart/form-data">
							<table align = "center" width= "80%" border="1" bgcolor="pink" cellpadding="8">
							<tr align="center">
							<td colspan="7"><h1>Add product</h2></td>
							</tr>
							
							<tr>
							<td align="right"><b>Product Title:</B></td>
							<td><Input type="text" name="product_title" size= "60" /> </td>
							</tr>
							
							<tr>
							<td align="right"><b>Product Category:</B></td>
							<td>
								<select name="product_cat" >
								<option>select A catogory</option>
								
								<?php

									$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 "<option value='$cat_id'>$cat_title</option>";
									}
									
								?>
								</select>
							</td>
							</tr>
							
							<tr>
							<td align="right"><b>Product Brand:</B></td>
							<td> <select name="product_brand" / >
							<option>Select Any Brand</option>
							<?php
							$get_brand ="SELECT * FROM `brands`";
	
							$run_brand = mysqli_query($con, $get_brand);
	
							while ($row_brand=mysqli_fetch_array($run_brand)){
		
							$brand_id = $row_brand['brand_id'];
							
							$brand_title =$row_brand['brand_title'];
		
							echo "<option value='$brand_id'>$brand_title</option>";
							}
							?>
							</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 (Inr):</B></td>
							<td> <Input type="text" name="product_price" size= "60"/> </td>
							</tr>
							
							<tr>
							<td align="right"><b>Product Descriptions:</B></td>
							<td> <textarea name="product_desc" 	cols="20" rows="10" > </textarea> </td>
							</tr>
							
							<tr>
							<td align="right"><b>Product Keyword:</B></td>
							<td> <Input type="text" name="product_keywords"/> </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 details of 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
					$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_id`, `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_product= mysqli_query($con, $insert_product);

				
echo "<script>alert('done')</script>";
echo "<script>window.open('insert_product.php','_self')</script>";	
	}
				
?>
 
iam getting the succes message
and also getting the image on specific folder.
 
1.pngHello forum!

People i'm having similar issues with this code. Nothing happens when i press submit button. No error messages, expecting an echo.

thank you very much




Code:
<!DOCTYPE html>
<?php
include ("includes/db.php");



?>


<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>insert_product</title>

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

<table align="center" >

<tr align="center">
    <td><h2>Insert new post</h2></td>

</tr>

<tr>
    <td>jewellery type</td>
    <td>
        <select name="j_type" >
<option >Select jewellery type</option>
<?php
$get_cats="select * from product";
$run_cats=mysqli_query($con, $get_cats);

while($row_cats=mysqli_fetch_array($run_cats)){

    $cat_id=$row_cats['product_id'];
    $cat_type=$row_cats['j_type'];
    echo"<option value'$cat_id>$cat_type</option>";
}


?>
        </select>
    </td>
</tr>
<tr>
    <td>stone name</td>
    <td><input type="text" name="stone_name"/></td>
</tr>
<tr>
    <td>stone price</td>
    <td><input type="text" name="stone_price"/></td>
</tr>
<tr>
    <td>product image</td>
    <td><input type="file" name="product_image"/></td>
</tr>
<tr>
    <td>stone color</td>
    <td><input type="text" name="stone_color"/></td>
</tr>

    
    <td ><input type="submit" name="insert_post" value="Insert now"/></td>
</tr>


</table>
    
</body>
</html>

<?php 



// // Create connection
// $conn = new mysqli();
// // Check connection
// if ($conn->connect_error) {
//    die("Connection failed: " . $conn->connect_error);
// }
//   echo "Connected successfully";


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

$j_type=$_POST['j_type'];
$stone_name=$_POST['stone_name'];
$stone_price=$_POST['stone_price'];
$stone_color=$_POST['stone_color'];

$product_image=$_FILES['product_image']['name'];
$product_image_tmp=$_FILES['product_image']['tmp_name'];


echo $insert_product="insert into product (j_type,stone_name,stone_price,stone_color,product_image) values ('$j_type','$stone_name','$stone_price','$stone_color','$product_image')";

// $insert_product = "insert into product
// (j_type,stone_name,stone_price,stone_color,product_image)

// VALUES('$j_type,'$stone_name',$stone_price','$stone_color','$product_image')";
		
				
}	




?>
 
Have you set errors to display?

Is that the code for two files?

Have you checked the resultant html code (the one that is displayed in your browser)?

Have you written all of this code or is it a copy, paste and hope?
 
hyper said:
Have you set errors to display?

Is that the code for two files?

Have you checked the resultant html code (the one that is displayed in your browser)?

Have you written all of this code or is it a copy, paste and hope?

1. I did change php.ini file by adding E_ALL in error reporting sentence.No errors

2. At the beginning of the code there is a link to other file that contains this line
Code:
 <?php
    $con= mysqli_connect("localhost","root","","ecommerce");
?>

3. i just did check the resultant html code. What should i be looking for?

4. I'm following tutorial..the teacher had same problem...but he resolved it by removing "required" attribute for the fields, which i never inserted on first place.

hope. i do hope.

Ready to pay a reasonable rate for tutoring me towards a good looking website.
 
1. I did change php.ini file by adding E_ALL in error reporting sentence.No errors
That sets what is reported, not what I asked: have you set it to display errors? If this is a public web site then you must set it to log errors and read the log file, location can be obtained from phpinfo()

2. At the beginning of the code there is a link to other file that contains this line
Again, not what I asked; the code that you put in your post: is that for two files or is it just one?

if one file, what is it called, if it's two files what are they called?

3. i just did check the resultant html code. What should i be looking for?
Correctly formed html that is exactly what you thought it would be

4. I'm following tutorial..the teacher had same problem...but he resolved it by removing "required" attribute for the fields, which i never inserted on first place.
:help: Find another tutorial, forget anything it did, if you paid for this, ask for your money back - I've heard it all now

When learning coding: Learn to read what is written, question it, read again, question more; repeat, rinse and repeat.

:?
 
1. Seems like display is on. Refer to images attached on one of the screenshots. On other screenshot error is on purpose ,just to see that the error display is showing2.png

2. This code is used in insert_page.php file only. 1file.

3. I'm not sure if html formed correctly.Shows up ok.
Code:
<!DOCTYPE html>
<?php
include("functions/functions.php");
?>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Ecommerce</title>
    <link rel="stylesheet" href="styles/styles.css" media="all"/>
</head>
<body>
 <div class="main_wrapper">

 <div class="header"></div>
 <div class="menu">
     
     <ul id="stones">

     <?php getCats() ?>
         

    </ul> 
     
 </div>
 

 <div class="footer">footer</div>

 </div>
</body>
</html>

4. Please help and dont get angry.
 
Well done for jumping the gun and proving error reporting is working :)

If the first listing (you posted) is producing the second listing, you have serious problems.

Are you typing "localhost/insert_page.php" into the address bar of your browser?
and
is that the code from the first code you posted?
and
(finally) is that file in your web root directory (the same place as oops.php)

Where did you get the second listing from?

I'm not getting angry, I'm laughing :D
 
1. By listing you mean this code?
Code:
echo $insert_product="insert into product (j_type,stone_price,product_image,stone_name,stone_color) values ('$j_type','$stone_price','$product_image','$stone_name','$stone_color')";


2.Are you typing "localhost/insert_page.php" into the address bar of your browser?
yes

3.is that the code from the first code you posted?
i posted only one php code. I compared it to original code by surajshrma12
and din't dind major differences except in this line
Code:
echo $insert_product="insert into product (j_type,stone_price,product_image,stone_name,stone_color) values ('$j_type','$stone_price','$product_image','$stone_name','$stone_color')";
Code:
VALUES([$product_cat],[$product_brand],[$product_title],[$product_price],[$product_desc],[$product_image],[$product_keywords])";

			$insert_product= mysqli_query($con, $insert_product);
is that file in your web root directory (the same place as oops.php)
4. 3.png
 
This first listing:
Code:
<!DOCTYPE html>
<?php
include ("includes/db.php");
?>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>insert_product</title>

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

Is not the same as the second listing you gave:
Code:
<!DOCTYPE html>
<?php
include("functions/functions.php");
?>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Ecommerce</title>
    <link rel="stylesheet" href="styles/styles.css" media="all"/>
</head>
<body>
 <div class="main_wrapper">
 ....

Can you post a screenshot of when you type the address in your browser to execute the script.
 
And can you also post a screenshot of the script in your editor (just what's on the screen will do; make sure that there isn't any sensitive information on the screen.
 
You are right it's not the same.Sorry for confusion.
1st listing insert_product.php listing, the 2nd listing is index.php file which is irrelevant in a problem i'm having.I provided it in attempt to your comment.
Have you checked the resultant html code (the one that is displayed in your browser)?


Can you post a screenshot of when you type the address in your browser to execute the script.

4.png

And can you also post a screenshot of the script in your editor (just what's on the screen will do; make sure that there isn't any sensitive information on the screen.
5.png
 
When processing forms using the same script, it's usual to put the checks at the top, put this bit at the top of your file and see what happens

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

$j_type=$_POST['j_type'];
$stone_name=$_POST['stone_name'];
$stone_price=$_POST['stone_price'];
$stone_color=$_POST['stone_color'];

$product_image=$_FILES['product_image']['name'];
$product_image_tmp=$_FILES['product_image']['tmp_name'];

echo $insert_product="insert into product (j_type,stone_name,stone_price,stone_color,product_image) values ('$j_type','$stone_name','$stone_price','$stone_color','$product_image')";

exit('<br>The button was pressed');
}
 
No luck
Take a look in code maybe i didn't understand you
Code:
<!DOCTYPE html>
<?php
include ("includes/db.php");
if(isset($_POST['insert_post'])){

    $j_type=$_POST['j_type'];
    $stone_name=$_POST['stone_name'];
    $stone_price=$_POST['stone_price'];
    $stone_color=$_POST['stone_color'];
    
    $product_image=$_FILES['product_image']['name'];
    $product_image_tmp=$_FILES['product_image']['tmp_name'];
    
    echo $insert_product="insert into product (j_type,stone_name,stone_price,stone_color,product_image) values ('$j_type','$stone_name','$stone_price','$stone_color','$product_image')";
    
    exit('<br>The button was pressed');
    }
    



?>


<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>insert_product</title>

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

<table align="center" >

<tr align="center">
    <td><h2>Insert new post</h2></td>

</tr>

<tr>
    <td>jewellery type</td>
    <td>
        <select name="j_type" >
<option >Select jewellery type</option>
<?php
$get_cats="select * from product";
$run_cats=mysqli_query($con, $get_cats);

while($row_cats=mysqli_fetch_array($run_cats)){

    $cat_id=$row_cats['product_id'];
    $cat_type=$row_cats['j_type'];
    echo"<option value='$cat_id'>$cat_type</option>";
}


?>
        </select>
    </td>
</tr>
<tr>
    <td>stone name</td>
    <td><input type="text" name="stone_name"/></td>
</tr>
<tr>
    <td>stone price</td>
    <td><input type="text" name="stone_price"/></td>
</tr>
<tr>
    <td>product image</td>
    <td><input type="file" name="product_image"/></td>
</tr>
<tr>
    <td>stone color</td>
    <td><input type="text" name="stone_color"/></td>
</tr>

    
    <td ><input type="submit" name="insert_post" value="Insert now"/></td>
</tr>


</table>
    
</body>
</html>
 
Back
Top