Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

I am facing a problem while uploading the images in database using php
Please help me out.

Below is code:-

ob_start();
$image=$_FILES['image']['name'];
$msg="";
if(isset($_POST['submit']))
{
include("dbconnect.php");
$image=$_FILES['image']['name'];
$item_heading=$_POST['item_heading'];
$item_size=$_POST['item_size'];
$item_content=$_POST['item_content'];
$item_type=$_POST['item_type'];
$item_sale_price=$_POST['item_sale_price'];
$item_regular_price=$_POST['item_regular_price'];
$item_catagory=$_POST['item_catagory'];
$loc=$_POST['item_location'];
$pos=$_POST['item_position'];
move_uploaded_file($_FILES["image"]["tmp_name"],"/hi/".$_FILES["image"]["name"]);

//insert the values in database
$sqlin=mysql_query("insert into add_item(item_page,item_type,item_pos,item_size,item,item_heading,item_content,   	item_sale_price,item_regular_price,item_catagory) values('$loc','$item_type','$pos','$item_size','$image','$item_heading','$item_content','$item_sale_price','$item_regular_price','$item_catagory')");
/*echo 
$sqlin=mysql_query("insert into add_item(item_page,item_type,item_pos,item_size, item, item_heading,item_content,   	item_sale_price,item_regular_price,item_catagory) values('".$item_location."','".$item_type."','".$pos."','".$item_size."','".$item."','".$item_heading."','".$item_content."','".$item_sale_price."','".$item_regular_price."','".$item_catagory."',)");
exit();*/
if($sqlin)
{
	$ms="Data Saved";
	header("location:manage_item.php?ms=$ms");
}
}
ob_end_flush();
?>

XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Add Item</title>
<style type="text/css">
<!--
.style1 {
	color: #FFFFFF;
	font-weight: bold;
}
-->
</style>
</head>
<body>
<form name="item_form" action="add_item.php" method="post">
<table width="341" border="1" align="center">
  <tr>
    <td height="32" colspan="2" bordercolor="#FFFFFF" bgcolor="#0000FF"><div align="center" class="style1">ADD ITEM</div></td>
  </tr>
  <tr>
    <td width="131">Choose Page</td>
    <td width="194"><select name="item_location" style="width:100px;">
      <option>Home</option>
      <option>Internal</option>
  </select>    </td>
  </tr>
  <tr>
    <td width="131">Select Catagory</td>
    <td><select name="item_catagory" style="width:100px;">
      <option>Helicopter</option>
      <option>Car</option>
      <option>Spare Part</option>
       </select></td>
  </tr>
  <tr>
    <td>Select Position</td>
    <td><select name="item_position" style="width:100px;">
    <option>Left</option>
    <option>Right</option>
    <option>Top</option>
    <option>Bottom</option>
    </select>    </td>
  </tr>
  <tr>
    <td>Select Item Size</td>
    <td><select name="item_size">
    <option>10px</option>
    <option>12px</option>
    <option>14px</option>
    <option>16px</option>
    <option>18px</option>
    <option>20px</option>
    <option>22px</option>
    <option>14px</option>
    <option>26px</option>
    </select>    </td>
  </tr>
  <tr>
    <td>Upload</td>
    <td>   <input type="file" name="image" size="20" /></td>
  </tr>
  <tr>
    <td>Image <input type="radio" name="item_type" value="image" /></td>
    <td>Video 
      <input type="radio" name="item_type" value="video" /></td>
  </tr>
  <tr>
    <td>Heading</td>
    <td><input type="text" name="item_heading" value="" /></td>
  </tr>
  <tr>
    <td>Content</td>
    <td><textarea name="item_content" cols="17" rows="3"></textarea></td>
  </tr>
  <tr>
    <td>Sale Price</td>
    <td><input type="text" name="item_sale_price" value="" /></td>
  </tr>
  <tr>
    <td>Regular Price</td>
    <td><input type="text" name="item_regular_price" value="" /></td>
  </tr>
  <tr>
    <td> </td>
    <td><input type="submit" name="submit" value="ADD ITEM" /></td>
  </tr>
</table>

</form>
</body>
</html>


Regards,
Shiana
Posted
Updated 31-Jul-10 3:49am
v2
Comments
Sandeep Mewara 31-Jul-10 9:50am    
Formatted code for better readability. Use PRE tags to format code part.
Peter_in_2780 1-Aug-10 19:46pm    
OK. There's your code. Now what is the problem? What error messages do you get? Where - browser, server error log? We need to know what goes wrong before we can suggest a fix.
shiana87 2-Aug-10 8:54am    
thanks this problem has been sorted out .Thanks

1 solution

The uploading of images to the database increases the size of the database where the images are of large size.
So my suggestion is just store the path of the image in the database and upload it to some of your web folder and make secure it.
 
Share this answer
 

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