<body>
<div class="box">
<form action="" method="POST" enctype="multipart/form-data">
<h3>add new product</h3>
<input type="text" class="box" required placeholder="enter product name" name="name">
<input type="number" min="0" class="box" required placeholder="enter product price" name="price">
<textarea name="details" class="box" required placeholder="enter product details" cols="30" rows="10"></textarea>
<input type="file" accept="image/jpg, image/jpeg, image/png" required class="box" name="image">
<input type="submit" value="add product" name="sub" class="btn">
</form>
</div>
</body>
</html>
<?php
if(isset($_POST['sub'])){
$name = mysqli_real_escape_string($conn, $_POST['name']);
$price = mysqli_real_escape_string($conn, $_POST['price']);
$details = mysqli_real_escape_string($conn, $_POST['details']);
$image = $_FILES['image']['name'];
$image_size = $_FILES['image']['size'];
$image_tmp_name = $_FILES['image']['tmp_name'];
$image_folter = 'uploaded_img/'.$image;
$select_product_name = mysqli_query($conn, "SELECT name FROM `p` WHERE name = '$name'") or die('query failed');
if(mysqli_num_rows($select_product_name) > 0){
$message[] = 'product name already exist!';
}else{
$insert_product = mysqli_query($conn, "INSERT INTO `p`(name, details, price, image) VALUES('$name', '$details', '$price', '$image')") or die('query failed');
if($insert_product){
if($image_size > 2000000){
$message[] = 'image size is too large!';
}else{
move_uploaded_file($image_tmp_name, $image_folter);
$message[] = 'product added successfully!';
}
}
}
}
output :
Notice: Undefined index: name in C:\xampp\htdocs\server\test to fix my problems\index.php on line 29
Notice: Undefined index: price in C:\xampp\htdocs\server\test to fix my problems\index.php on line 30
Notice: Undefined index: details in C:\xampp\htdocs\server\test to fix my problems\index.php on line 31
Notice: Undefined index: image in C:\xampp\htdocs\server\test to fix my problems\index.php on line 32
Notice: Undefined index: image in C:\xampp\htdocs\server\test to fix my problems\index.php on line 33
Notice: Undefined index: image in C:\xampp\htdocs\server\test to fix my problems\index.php on line 34