The below program is not working.
add_product.php
<?php
$name=$_REQUEST["txtname"];
$price=$_REQUEST["txtprice"];
$category=$_REQUEST["ddlcategory"];
$weight=$_REQUEST["txtweight"];
$description=$_REQUEST["txtdescription"];
$img=$_REQUEST["btnimage"];
$connect=mysql_connect("localhost","root","","CakeShop") or die(mysql_error());
echo "Connected..";
mysql_select_db(CakeShop);
if(isset($_REQUEST['btnadd']))
{
//The if loop gets executed even if the image is selected....!
if(getimagesize($Files['btnimage']['tmp_name'])==FALSE)
{
$message="Please select an image";
echo "<script type='text/javascript'>alert('$message');</script>";
}
else
{
$insert="Insert into tblProduct(p_name,p_price,p_category,p_weight,p_description,p_image) values ('$name','$price','$category','$weight','$description','$img');";
mysql_query($insert) or die("Failed to insert data");
echo "<h3>Product Details Inserted........</h3>";
}
}
mysql_close();
?>
add_product.html
<html>
<head>
<title>Cake Central</title>
</head>
<body>
<h1>ADD NEW PRODUCT</h1>
<hr>
<form method="post" action="add_product.php">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="txtname"></td>
</tr>
<tr>
<td>Price:</td>
<td><input type="text" name="txtprice"></td>
</tr>
<tr>
<td>Category:</td>
<td>
<select name="ddlcategory">
<option>Veg</option>
<option>Non-Veg</option>
</select>
</td>
</tr>
<tr>
<td>Weight:</td>
<td><input type="text" name="txtweight"></td>
</tr>
<tr>
<td>Description:</td>
<td><textarea rows="2" cols="16" name="txtdescription"></textarea></td>
</tr>
<tr>
<td>Image:</td>
<td><input name="btnimage" type="file" /></td>
</tr>
<tr>
<td><input class="btn" type="submit" name="btnadd" value=" Add "></td>
</tr>
</table>
</form>
</body>
</html>