Jump to content

File Upload Trouble


bluebyyou

Recommended Posts

I'm working on a site for a fireman calendar. I'm trying to set it up so that the guys at the firehouse can go in and add the bio's and photos of the new fireman with out me every year. I have a script that works to upload an image, as long as the only field in my form is the file field. However now that I am mixing all these other form fields the file info seems to be getting lost somewhere when it is submitted.  As you can see in my code im doing print_r($_POST) and print_r($_FILES) to see whats happening, but I still can figure what is happening to all the file info when the form is submitted. The first half of the script is the form, the second half is the stuff to insert it into the DB. My upload script is in another file, I havent included it here yet until I can figure out what is happening to the file info. Does anyone have any ideas, or advice?

 

<?php
session_start();

if ($_SESSION['auth'] == "admin") 
{
include("db_connect.php");

if ($_POST['action'] == "addfiremen")
{
	echo "<h1>Add Firemen for ".$_POST['year']."</h1>";
	echo "<form name='add_firemen' action='".$_SERVER['PHP_SELF']."' method='post'>";
	echo "<input name='action' type='hidden' value='add' />";
	echo "<input name='number' type='hidden' value='".$_POST['number']."' />";

	for ( $counter = 1; $counter <= $_POST['number']; $counter += 1) 
	{
		echo "<table><tr><td>";
		echo "<input name='".$counter."[counter]' type='hidden' value='".$counter."' />";
		echo "<input name='".$counter."[year]' type='hidden' value='".$_POST['year']."' />";
		echo "First Name:<input name='".$counter."[first_name]'  size='16' type='text' /><br /><br /> ";
		echo "Last Name:<input name='".$counter."[last_name]'  size='16' type='text' /><br /><br />";
		echo "Job:<input name='".$counter."[job]'  size='40' type='text' /><br /><br />";
		echo "Picture:<input name='".$counter."[picture]' type='file'><br /><br />";
		echo "Thumbnail:<input name='".$counter."[thumbnail]' type='file'><br /><br />";
		echo "</td>";
		echo "<td>";
		echo "Story: <br />";
		echo "<textarea name='".$counter."[info]' cols='60' rows='15'></textarea><br><br>";
		echo "</td></tr><tr><td colspan='2'><hr /></td></tr></table>";

	}
	echo "<input name='submit' type='submit' value='Submit'>";
	echo "</form>";

}
else if ($_POST['action'] == 'add')
{
	include("upload_action.php");

	print_r($_POST);
	echo "<br />";
	print_r($_FILES);
	echo "<br />";

	for ( $counter = 1; $counter <= $_POST['number']; $counter += 1) 
	{
		$calendar_year = addslashes(strip_tags($_POST[$counter]['year']));
		$calendar_fname = addslashes(strip_tags($_POST[$counter]['first_name']));
		$calendar_lname = addslashes(strip_tags($_POST[$counter]['last_name']));
		$calendar_job = addslashes(strip_tags($_POST[$counter]['job']));
		$calendar_info = addslashes(strip_tags($_POST[$counter]['info']));


		$insert_query = "INSERT INTO calendar (`calendar_year`, `calendar_fname`,`calendar_lname`,`calendar_job`,`calendar_info`) VALUES 		
											  ('$calendar_year','$calendar_fname','$calendar_lname','$calendar_job','$calendar_info')";
		//$insert_result = mysql_query($insert_query) or die(mysql_error());

		echo $insert_query."<br />";
	}
	header ('location:index.php?page=calendars');
}
}
else { include("log_form.php"); }		
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.