/    Sign up×
Community /Pin to ProfileBookmark

says Image field is not filled in (but it is)

Hi guys. If you go here: [url]http://kmkwebdevelopment.com/testform/contact.php[/url] and fill out the form and input 4 images, when you submit, it will say “You have not filled this filed(s): Image.” However, I do fill them in with 4 images. Does anyone know why this is happening? Here is the PHP code:

[code=php]<?php
$nasaadresa = “[email protected]”; //please replace this with your address

$mail = $_POST[‘Email’];
$porukaa = $_POST[‘Image’];
$poruka = str_replace(“r”, ‘<br />’, $porukaa);
//START OF THANKS MESSAGE
//you may edit $thanks message. this is a message which displays when user sends mail from your site
$thanks = ”
<p align=’left’><br>
<b>Your message has been sucessfuly sent!<br></b>

</p>”;
//do not edit nothing below this line until comment (ME) say so if you don’t have skills with PHP
//END OF THANKS MESSAGE

if($_POST[‘submitform’])
{

$Name = $_POST[‘Name’];
$Email = $_POST[‘Email’];
$Image = $_POST[‘Image’];
$require = $_POST[‘require’];
$browser = $HTTP_USER_AGENT;
$ip = $_SERVER[‘REMOTE_ADDR’];

$dcheck = explode(“,”,$require);
while(list($check) = each($dcheck))
{
if(!$$dcheck[$check]) {
$error .= “<br /><br />You have not filled this filed(s): <b>$dcheck[$check]</b>.<br>”;
}
}
if ((!ereg(“.+@.+..+”, $Email)) || (!ereg(“^[[email protected]]+$”, $Email))){
$error .=”Wrong e-mail.<br>This e-mail address <b>$Email</b> – is not valid. Please enter correct e-mail address.”;
}
if($error)
{
echo $error;
echo ‘<br><a href=”#” onClick=”history.go(-1)”>Please try again.</a>’;
}
else
{
//START OF INCOMING MESSAGE (this message goes to your inbox)
$message = ”
Name: $Name:
E-mail: $Email

Image: $Image

—————————–
Browser: $browser
IP: $ip
“;
//END OF INCOMING MESSAGE (this message goes to your inbox)

$subject = “Message from Class Clean Svc. Website – Message was sent by $Name”; //subject OF YOUR INBOX MESSAGE sent to you

$subject2 = “You have succesfully sent message from Class Clean Svc. Website!”; //subject of OUTGOING MESSAGE – edit this
//OUTGOING MESSAGE TEXT
$message2 = “You have sent a message to site admin:
—————————–
From: $Name:
E-mail: $Email

Image: $Image

—————————–
“;
//END OF outgoing MESSAGE

mail($nasaadresa,”$subject”,”$Image”,”From: $Name <$Email>”);
mail($Email,”$subject2″,”$message2″,”From: <$nasaadresa>”);
echo “$thanks”;
}
}
else{
//this is contact form down here, please edit if you know what are you doing… or the contact form may not be working.
echo ‘
<form name=”contactform” enctype=”multipart/form-data” action=”‘.$PHP_SELF.'” method=”post”>
<input type=”hidden” name=”require” value=”Name,Email,Image”>
<table width=”444″ align=”center”>
<tr>
<td colspan=”2″ align=”center”>
<p></td>
</tr>
<tr>
<td valign=”top” align=”right”><b>Name:</b></td>
<td valign=”top”>
<input name=”Name” size=”30″>
</td>
</tr>
<tr>
<td valign=”top” align=”right”><b>E-mail:</b></td>
<td valign=”top”>
<input name=”Email” size=”30″
</td>
</tr>
<tr>
<td valign=”top” align=”right”><b>Image:</b></td>
<td valign=”top”>
<input type=”file” name=”Image”>
</td>
</tr>
<tr>
<td valign=”top” align=”right”><b>Image:</b></td>
<td valign=”top”>
<input type=”file” name=”Image”>
</td>
</tr>
<tr>
<td valign=”top” align=”right”><b>Image:</b></td>
<td valign=”top”>
<input type=”file” name=”Image”>
</td>
</tr>
<tr>
<td valign=”top” align=”right”><b>Image:</b></td>
<td valign=”top”>
<input type=”file” name=”Image”>
</td>
</tr>
<tr>
<td colspan=”2″ align=”center”><p align=”right”><br>
<input type=”submit” value=”Send” name=”submitform”>
<input type=”reset” value=”Reset” name=”reset”></p>
</td>
</tr>
</table>
</form>’;
}
?>
</div>
</body>
</html>
[/code]

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@aj_nscSep 24.2009 — PHP uses a special superglobal - $_FILES - to pass file fields and associated data to the server, not $_POST.

Read up on it at http://us2.php.net/manual/en/reserved.variables.files.php
Copy linkTweet thisAlerts:
@CaptainkewlauthorSep 24.2009 — Thanks for the reply. So, would I then just replace $_POST with $_FILES to make it work. Forgive me, I am a novice in PHP (obviously).
Copy linkTweet thisAlerts:
@CaptainkewlauthorSep 24.2009 — I replaced the $_POST with $_FILES for the Image only and the message now said it was successfully sent. The problem now is that it does not send me the name, email address or the 4 images to my email box. It just sends me an email saying "Array".
Copy linkTweet thisAlerts:
@aj_nscSep 24.2009 — When I said read up about $_FILES and gave you a URL from php.net, what I meant is that you probably read up about $_FILES using the URL from php.net I provided you with. It will explain to you (in quite easy to understand terms) what $_FILES actually is and does.
Copy linkTweet thisAlerts:
@CaptainkewlauthorSep 24.2009 — I did read it, but I am having a bit of trouble making sense of it. Is what I am doing possible? (have user send me name, email and 4 images to my email inbox).
Copy linkTweet thisAlerts:
@aj_nscSep 24.2009 — First off, fields must have a unique name. You can't have four file fields each named Image because you won't be able to discern them from each other. Secondly, when a file is submitted to you, it has to be first uploaded to the server - a fantastic tutorial on how to do multiple uploads is located in this thread. Thirdly, the best option, I think, would be for them to send you an e-mail that contained four links to the images they just uploaded to your server, which can be generated once you handle all the file uploads.

Unfortunately, it's not as simple it looks like you though, although I'm sure you'll still be able to accomplish it. The file uploading is the most difficult thing you'll have to do, and that thread is fantastic in it's explanation.

Make sure you scroll down to the second post where it explains how to handle multiple file uploads.
Copy linkTweet thisAlerts:
@CaptainkewlauthorSep 24.2009 — Thanks for the info (much appreciated). I will get started reading it now.
Copy linkTweet thisAlerts:
@CaptainkewlauthorSep 24.2009 — That thread was great. So now I can upload images to my server. The only problem is, if I have say a guy named "Fred" that uploaded 4 images and a girl named "Wilma" that uploaded 4 images, how would I tell who uploaded which images? Is there a way to do that?
Copy linkTweet thisAlerts:
@aj_nscSep 24.2009 — You have to give them each a unique name. In your case, you could name them Fred-(uniqueid)-1.jpg, Fred-(uniqueid)-2.jpg, Wilma-(uniqueid)-1.jpg

It really doesn't matter what you name them, as long as they are unique names (if a file exists with the same name and you try and save it, then it will overwrite it and you will lose the first file). Name them however you want to name them when you get to the part of the script where you get to this part:

[code=php]
foreach($active_keys as $key)
{
$now = time();
while(file_exists($uploadFilename[$key] = $uploadsDirectory.$now.' '.$_FILES[$fieldname]['name'][$key]))
{
$now++;
}
}
[/code]


The part on the right side of the equals (=) sign is the filename, you can use something like:

[code=php]
foreach($active_keys as $key)
{
$now = time();
while(file_exists($uploadFilename[$key] = $uploadsDirectory.$now.' '.$_POST['Name'].'-'.$_FILES[$fieldname]['name'][$key]))
{
$now++;
}
}
[/code]


So if I entered the name Jim in your form and uploaded a file called DSC3056.jpg - it would get named as Jim-(some timestamp)-DSC3056.jpg

good luck.
Copy linkTweet thisAlerts:
@CaptainkewlauthorSep 24.2009 — Thanks for the info. I understand what your saying. I guess if I wanted the user to be able do upload images without re-naming them, I would have to set up some sort of user log in so that the images would go into separate user folders.
×

Success!

Help @Captainkewl spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...