Help with Image posting with form to database with php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Alleg
Forum Newbie
Posts: 1
Joined: Fri Jul 15, 2005 2:48 am

Help with Image posting with form to database with php

Post by Alleg »

Hello !
Im newbie to php . I want to post some data with form and Image or binary date i use the following code:
<form action="/CMS/Img.php" method="post" enctype="multipart/form-data" name="form1">
<INPUT type ="text" name="txtName" id="txtName">
<INPUT type ="image" src="../media/10.gif" name = "Img">
<INPUT name=Submit type=submit value=Submit>
<input name="Reset" type="reset" value="Reset">
</form>
the php Code:
$txtName = Trim($_POST["txtName"]) ;
$Img = $_POST["Img"] ;
$Query= "insert into product (Name ,Picture )
values ('$txtName','$Img')" ;
why i cant get the Img field from form
Can you help
Thanks very much
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Image input elements return name.x and name.y, which PHP translates into $_POST['name_x'] and $_POST['name_y']. They contain the coordinates of where the user clicked.

http://www.zend.com/manual/faq.html.php ... form-image

If the user clicks the submit button in your example instead of the image then there won't be anything returned for img. Likewise, if the user clicks the image, nothing will be returned for the submit button.
Post Reply