0

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>

Edited by Reverend Jim: Fixed formatting

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by hashinclude
0

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.

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.