Php Form Image & message problems!

Hi All

Can someone help me out here, I have put together for the first time (well chuffed) a php form for my site but I cant work out how:

  1. I get the upload images to work (i cant a find the process on the net that i understand - because im new to php)

  2. how i get 2 message boxes to submit different info

any help would be much appreciated

Here is all the code:

HTML PART

<strong>Photos / Images</strong><br />

Upload Photos / Images &lt;br /&gt;

&lt;input type="file" name="imgfile" id="imgfile" style="background: white; color: black; border-width: thin; ; border-style: solid; border-color: grey" value="Browse" /&gt;&lt;br /&gt;
&lt;input type="file" name="imgfile" id="imgfile" style="background: white; color: black; border-width: thin; ; border-style: solid; border-color: grey" value="Browse" /&gt;&lt;br /&gt;
&lt;input type="file" name="imgfile" id="imgfile" style="background: white; color: black; border-width: thin; ; border-style: solid; border-color: grey" value="Browse" /&gt;&lt;br /&gt;
&lt;input type="file" name="imgfile" id="imgfile" style="background: white; color: black; border-width: thin; ; border-style: solid; border-color: grey" value="Browse" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;

Description&lt;br&gt;
&lt;textarea rows="15" name="message" cols="60"&gt;&lt;/textarea&gt;&lt;br&gt;
&lt;br&gt;

Any other information that has not been included above&lt;br&gt;
&lt;textarea rows="15" name="message" cols="60"&gt;&lt;/textarea&gt;&lt;br&gt;
&lt;br&gt;

PHP PART

<?php
if(isset($_POST[‘submit’])) {

$to = "tg@gmail.com";
$subject = "Enquiry";
$name_field = $_POST['name'];
$email_field = $_POST['email'];


$message = $_POST['message'];
$message = $_POST['message'];


foreach($_POST['check'] as $value) {
$check_msg .= "Checked: $value\

";
}

$body = "From: $name_field\

E-Mail: $email_field
Description: $message

More Information: $message

$check_msg";

echo "Data has been submitted to $to!";
mail($to, $subject, $body);

} else {
echo “blarg!”;
}
?>

Well, first off, you’re going to run into problems having more than one input with the same name/id You can give radios the same name, but every id needs to be unique.

The input type=“file” are similar to the inputs going into $_POST variables, except they go into $_FILES variables http://www.php.net/manual/en/reserved.variables.files.php

<form enctype=“multipart/form-data” action=“YOURFILE.php”>

<input type=“file” name=“imgfile” id=“imgfile” style=“background: white; color: black; border-width: thin; ; border-style: solid; border-color: grey” value=“Browse” /><br />
<input type=“file” name=“imgfile” id=“imgfile” style=“background: white; color: black; border-width: thin; ; border-style: solid; border-color: grey” value=“Browse” />
<input type=“submit” value=“Upload”/>
</form>
Note: name=“imgfile” important

Now you can do this:


if(count($_FILES["imgfile"]['name'])>0 ) { 						
		for($j=0; $j < count($_FILES["imgfile"]['name']); $j++) { 
			 $temp_name = $_FILES["imgfile"]['tmp_name'][$j];
			 $type = $_FILES["imgfile"]['type'][$j];
			 $name = $_FILES["imgfile"]['name'][$j];
			 
			 //hadnle upload here
			 // db logic
		}
	}else{
		echo"Please uplaod atleast one image.";	
	}

multipart/form-data is very important

Thank you very much for your reply, can you please tell me what I do with the first line -

mine is

if(isset($_POST[‘submit’])) {

you have put

if(count($_FILES[“imgfile”][‘name’])>0 ) {

I dont understand php but i think i have worked out that ‘if’ is the beginning all php code (this means i have 2 ifs : (

Thanks in advance

Actually the PHP code is between <?php and ?>
although you may see “short tags” like <?= … ?> for <?php echo … ?>

Don’t worry about having 2 if conditional tests. My goodness there’s times when there gets to be so many of them I have to wonder if I should rethink things.

What and how to structure your conditional tests depends on the logic you want your code to take. Often this is more complicated that getting the syntax right.

What I usually do is write a kind of outline first and then fill in the code. eg.

if the form is submitted
…gather form input
…validate and sanitize input
…if input is good to go
…do stuff with it
…else
…output error message
else
…show input form

IMHO it pays to get the logic organized and thought out first.