bluebyyou Posted December 31, 2008 Share Posted December 31, 2008 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"); } ?> Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted December 31, 2008 Share Posted December 31, 2008 add this to your form tag: enctype="multipart/form-data" Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.