943,163 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 364
  • PHP RSS
Mar 15th, 2010
0

Image

Expand Post »
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>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Pooja J. is offline Offline
39 posts
since Feb 2010
Mar 15th, 2010
0
Re: Image
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.
Reputation Points: 13
Solved Threads: 13
Junior Poster
liamfriel is offline Offline
101 posts
since Oct 2009
Mar 15th, 2010
0
Re: Image
you need to access $_FILE instead of $_POST
it should be:
$file = $_FILE['file2']['name']
instead of
$file = $_POST['file2'];
Reputation Points: 11
Solved Threads: 8
Junior Poster
hashinclude is offline Offline
111 posts
since May 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: please help php error
Next Thread in PHP Forum Timeline: You have an error in your SQL syntax; check the manual that corresponds to your MySQL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC