Hi guys,
I have one form contains img title and img name, also in database named as gallary. my prob is i cant store the name of img with extension using file field.
plz, guide me.

//admin.php
<?php
$con = mysql_connect("localhost","root","");
$db = mysql_select_db('admin');

$title = $_POST['title'];
$file = $_POST['file2'];
echo $title;
echo $file;
$ext = explode('.',$file);
$submit = $_POST['submit'];

if(!empty($submit))
{
    $insert = "insert into gallery(title,file) values('$title','$file')";
    $query = mysql_query($insert);
} 
?>

<body>
<form action="admin.php" method="post" name="admin" id="admin" enctype="multipart/form-data">
<h2 align="center">Welcome to admin panel</h2>
<table width="75%" border="0" cellspacing="3" cellpadding="2">
  <tr>
    <td height="237"><table width="100%" border="0" cellspacing="3" cellpadding="2" bgcolor="#CCCCFF">
      <tr>
        <td>Add to Gallery</td>
      </tr>
      <tr>
        <td>Manage to Gallery</td>
      </tr>
    </table></td>
    <td align="right"><table width="100%" border="0" cellspacing="3" cellpadding="2">
      <tr>
        <td>Image Title</td>
        <td>
          <input type="text" name="title" id="title" />
        </td>
      </tr>
      <tr>
        <td>Image File</td>
        <td>

          <input type="file" name="file2" id="file2" />
        </td>
      </tr>
      <tr>
        <td colspan="2" align="center">
          <input type="submit" name="submit" id="submit" value="submit" />
        </td>
        </tr>
    </table></td>
  </tr>
</table>
</form>
</body>

The file fields do not get sent via $_POST - they are sent in PHP via $_FILE. there are various tutorials on uploading and changing files names.

you need to access $_FILE instead of $_POST
it should be:
$file = $_FILE
instead of
$file = $_POST;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.