Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

Why doesn't my form see this field?

My form is attached. When I've got an mp3 file in the mp3_file field, I submit it to this:

if(isset($_FILES['mp3_file']['name'])&& !empty($_FILES['mp3_file']['name']))
{
echo "yeah";
}

...and I get nothing. The field isn't being seen and I don't know why. Any thoughts?

 
<?php
session_start();
if (!isset ($_SESSION['sv_email'])) {               
header("Location:contestants_login.php");exit();
}
$sv_email=$_SESSION['sv_email'];
include("carter.inc"); 
$cxn = mysqli_connect($host,$user,$password,$database)or die ("couldn't connect to server");
$query = "select * from registration where email = '$sv_email'";
$result = mysqli_query($cxn, $query);

if(!$result) {$error = mysqli_errno($cxn).': '.mysqli_error($cxn);
die($error);
}
$row = mysqli_fetch_assoc($result);
extract($row);
$contestant_id = $id;
$contestant_radio_id = $radio_id;
$bio_text=$bio;
$contestant_first_name = $first_name;
$contestant_last_name = $last_name;
$contestant_primary = $primary_instrument;
$contestant_secondary = $secondary_instrument;
$contestant_stage_name = $stage_name;
$contestant_radio_name = $radio_name;
$contestant_artist_act = $artist_act;
$contestant_artist_music = $artist_music;
$contestant_security_question = $security_question;
$contestant_security_answer = $security_answer;
$the_password = $contestant_password;
$this_year = date("Y");
$contestant_lyrics = $lyrics;
$contestant_writer = $songwriting_contest;
$contestant_rules = $rules;
$contestant_mp3 = $mp3_file;
$contestant_year = $year;
$contestant_song_title = $song_title;
$contestant_hall = $fame;
$contestant_song_permission = $song_permission;



if(!empty($_GET['writer'])){
header("Location:contestants_editpage_write.php");
}

//this next block of code grabs the stage name or the first name of the contestant, depending if they have a stage name and determines whether or not there's an "s" at the end of the name so it can document that correctly
if(empty($contestant_stage_name)){
$display_name = $first_name;
}
else
{
$display_name = $contestant_stage_name;
}

$rest = substr("$display_name", -1);
if($rest=="s"){
$sweet_name = $display_name."'";
}
else
{
$sweet_name = $display_name."'s";
}

if(!empty($contestant_writer) AND $contestant_writer<> "0000-00-00"){
$songwriting_link = "contestants_editpage.php";
$songwriting=1;
}
else
{
$songwriting=0;
$songwriter_competitor=0;
$songwriting_link = "songwriting_intro.php?id=$contestant_id";
}

if($songwriting>0){
require_once('songwriting_admin.php');
require_once('songwriting_receipt.php');
require_once('songwriting_calendar.php');
require_once('songwriting_datecheck.php');
}

require_once('header.php');

?>

<body>
<table width=100% cellspacing="0" cellpadding="0">
<tr>
<td align="center" class="background">
	<table width="1000" cellspacing="0" cellpadding="0" border="0">
	<tr>
	<td><IMG SRC="images/spacer.gif" width="50" height="32">
	</td>
	<td><?php require_once('login_form.php'); ?></td>
	</tr>
	<tr>
	<td align="center" colspan="2">
	<?php require_once('flash_header.php'); ?>
	</td>
	</tr>
	<tr>
	<td colspan="2">&nbsp;<BR>
	</td>
	</tr>
	<tr>
	<td><IMG SRC="images/spacer.gif" width="50" height="32">
	</td>
	<td width="950" background="images/spacer.gif" width="950" width="32">
	<!- here's where you content goes, but you have to offset it a bit in order to accommodate the guitar that's technically hanging over the edge ->
		<table width="950" cellspacing="0" cellpadding="0">
		<tr>
		<!- here's where you've got your first column of info - this is your text ->
		<td width="592" valign="top">
			<?php require_once('contestant_menu.php'); ?>
			<!- here's all your content ->
			<td class="standard">&nbsp;<BR>
			Hello, <?php echo "$contestant_first_name"; ?>!
			<P>
			To make any changes to your Profile, simply alter the fields as you see them below, then click on "Update Page" at the very bottom of the page.
			<P>
			If you have any questions, contact <A HREF="Contact.php" class="body">SPI</a>.
			<P>
			Thanks!
			</td>
			</tr>
			<tr>
			<!-good ->
			
			<td>&nbsp;<BR>
				<table border="0">								
				<?php
				// this verbiage only shows up if the user is looking at their edit page without having first looked at the songwriting_intro.php page
				if($contestant_writer=="0000-00-00"){
				?>
				<tr>
				<td colspan="2">
				<div align="center"><b>If you're interested in competing in the Country Showdown Songwriting Competition, click <A HREF="songwriting_intro.php" class="body"><b>here</b></a></b>.
				</div>&nbsp;	<BR>
				</td>
				</tr>
				<?php
				}
				?>
				<?php
				// this verbiage only shows up if the user is looking at their edit page without having first looked at the songwriting_intro.php page
				if($contestant_rules=="0000-00-00"){
				?>
				<tr>
				<td colspan="2">
				<font size="1"><b>If you're interested in competing in the Country Showdown , click <A HREF="contestants_editpage_show.php" class="body"><font size="1"><b>here</b></font></a></b>.
				</td>
				</tr>
				<?php
				}
				?>
				<form enctype="multipart/form-data" action="contestants_edit_execute_test.php" method="POST">	
				<tr>
				<td background="images/spacer.gif" width="195" height="10" class="standard">
				Stage Name
				</td>
				<td>
				<input type="text" size="50" name="stage_name" value="<?php echo "$contestant_stage_name"; ?>">
				</td>
				</tr>
				<tr>
				<td class="standard">
				Primary Instrument
				</td>
				<td>
				<select name="primary_instrument">
				<option selected><?php echo "$primary_instrument"; ?></option>
				<option>Singer</option>
				<option>Guitar</option>
				<option>Banjo</option>
				<option>Mandolin</option>
				<option>Steel Guitar</option>
				<option>Bass</option>
				<option>Fiddle</option>
				<option>Keys</option>
				<option>Harp</option>
				<option>Drums</option>
				<option>___________________________________________</option>
				</td>
				</tr>
				<tr>
				<td class="standard">
				Secondary Instrument
				</td>
				<td>
				<select name="secondary_instrument">
				<option selected><?php echo "$secondary_instrument"; ?></option>
				<option>Singer</option>
				<option>Guitar</option>
				<option>Banjo</option>
				<option>Mandolin</option>
				<option>Steel Guitar</option>
				<option>Bass</option>
				<option>Fiddle</option>
				<option>Keys</option>
				<option>Harp</option>
				<option>Drums</option>
				<option>___________________________________________</option>
				</td>
				</tr>
				<tr>
				<td class="standard">
				Describe your act
				</td>
				<td>
				<select name="artist_act">
				<option selected><?php echo $contestant_artist_act; ?></option>
				<option>Soloist</option>
				<option>Duo</option>
				<option>Band</option>
				<option>___________________________________________</option>
				</td>
				</tr>
				<tr>
				<td class="standard">
				Describe your music
				</td>
				<td>
				<select name="artist_music">
				<option selected><?php echo $contestant_artist_music; ?></option>
				<option>Classic Country</option>
				<option>Country Pop</option>
				<option>Southern Rock</option>
				<option>Crossover</option>
				<option>Blues</option>
				<option>___________________________________________</option>
				</td>
				</tr>
				<tr>
				<td background="images/spacer.gif" width="180" height="10" class="standard">
				Password
				</td>
				<td>
				<input type="text" size="50" name="password" value="<?php echo $the_password; ?>">
				</td>
				</tr>
				<tr>
				<td class="standard">
				Security Question
				</td>
				<td>
				<select name="security_question">
				<option selected><?php echo stripslashes($contestant_security_question); ?></option>
				<option>What's your mother's maiden name?</option>
				<option>What's the name of the street you grew up on?</option>
				<option>What was the name of your first pet?</option>
				<option>___________________________________________</option>	
				</td>
				</tr>
				<tr>
				<td class="standard">
				Security Question Answer
				</td>
				<td>
				<input type="text" size="50" name="security_answer" value="<?php echo stripslashes($contestant_security_answer); ?>">
				</td>
				</tr>
				<tr>
				<td class="standard">
				Upload Photo
				</td>
				<td>
				<font color="white"><input name="photo" type="file" size="37"></font>
				</td>
				</tr>												
				<tr>												
				<td colspan="2" class="standard">						
				<font size="1"><b>When you upload your photo, be sure that it's no more than 150 px across and no more than 160 px high.</b></font>						
				</td>						
				</tr>
				
				<tr>
				<td class="standard">
				mp3
				</td>
				<td>
				<input name="mp3_file" type="file" size="37">
				</td>
				</tr>
				<tr>												
				<td colspan="2" class="standard">						
				<font size="1"><b>Only original music please! No covers.</b></font>						
				</td>						
				</tr>
				
				<tr>
				<td class="standard">
				Song Title
				</td>
				<td>
				<input type="text" size="50" name="song_title" value="<?php echo stripslashes($contestant_song_title); ?>">
				</td>
				</tr>
				<?php
				if($contestant_song_permission=="0000-00-00" OR $contestant_song_permission=="" OR $contestant_song_permission==" " OR empty($contestant_song_permission))
				{
				?>
				<tr>
				<td colspan="2" class="standard">&nbsp;<BR>
					<table width="592" border="1" cellspacing="2" cellpadding="2">
					<tr>
					<td>
					<font color="white">I have read and understood the guidelines and conditions surrounding the posting of original music on countryshowdown.com. Click <A HREF="originals.php" target="_blank" class="body">here</a> for more details.</font>
					</td>
					<td align="center" background="images/spacer.gif" width="50" height="10">
					<input type="checkbox" value="Y" name="originals">
					</td>
					</tr>
					</table>
				</td>
				</tr>
				<?php
				}
				?>
				<?php 
				if($contestant_writer<>"0000-00-00"){
				?>
				<tr>
				<td colspan="2" class="standard"><input type="hidden" name="songwriter" value="1">&nbsp;<BR>
					<?php
					if(!empty($contestant_lyrics)){
					?>
					<textarea name="lyrics" class="Contestant"><?php echo stripslashes($contestant_lyrics); ?></textarea>
					<?php
					}
					else
					{
					?>
					<textarea name="lyrics" class="Contestant">Put your song lyrics here...</textarea>
					<?php
					}
					?>
				</td>
				</tr>
				<?php
				}
				?>
				<tr>
				<td colspan="2">&nbsp;<BR>
				
				<?php
				
				if($bio_text==""){
				$bio="Complete your Bio here (background, musical experience, hobbies etc.)";
				}
				else
				{
				$bio=stripslashes($bio_text);
				}
				?>
				
				<textarea name="bio" class="Contestant"><?php echo "$bio"; ?></textarea>
				</td>
				</tr>
				
				<?php include("contestant_calendar_code_edit.php"); ?>
				
				<tr>
				<td colspan="3">&nbsp;<BR>&nbsp;<BR>
				</td>
				</tr>
				<tr>
				<td colspan="3" align="center">
				<input type="image" src="images/update_page.jpg" border="0" name="submit"></form>
				</td>
				</tr>
				
				<tr>
				<td colspan="2">
				&nbsp;<BR>
				</td>
				</tr>
				
				<tr>
				<td style="width: 100%; height: 100%; vertical-align: top; border: solid 1px white;" colspan="2"> 
				If you're uploading an mp3 file, understand that it can take a while. So be sure you hit "Submit" only once and then wait. Your file is being uploaded, but it can take up to 
				5 minutes depending on the size of the file and your connection speed.
				</td>
				</tr>
				<tr>
				<td colspan="2">
				&nbsp;<BR>
				</td>
				</tr>
				</table>
			</td>
			</tr>
			</table>
		</td>
		<td>
		<IMG SRC="images/spacer.gif" width="36" height="32">
		</td>
		<td width="302" valign="top"><!- this batch of code houses the contestant's stats, jukebox, calendar etc. -> 
		<?php require_once('contestant_column.php'); ?>
		</td>
		</tr>
		</table>
	</td>
	</tr>
	<?php require_once('footer.php'); ?>
	</table>
</td>
</tr>
</table>

</body>
</html>

Open in new window

Avatar of Rik-Legger
Rik-Legger
Flag of undefined image

Try debugging your $_FILES array by showing what it holds.
At first sight your code seems ok.

echo '<pre>'.print_r($_FILES,1).'</pre>';

Open in new window

Avatar of Bruce Gust

ASKER

This is what I put at the top of the page:

<?php
echo '<pre>'.print_r($_FILES,1).'</pre>';
if(isset($_FILES['mp3_file']['name'])&& !empty($_FILES['mp3_file']['name']))
{
echo "yeah";
}

...and I got nothing.
SOLUTION
Avatar of Rik-Legger
Rik-Legger
Flag of undefined image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here's what I get:

Array
(
)

Array
(
)

You putted the code in the file where your posting it to? (contestants_edit_execute_test.php)
Because the debugging tells me it shows no posting data.
Did you put the testing code in top of the file, because maybe some other code overwrites your post en files data.
Try debugging line by line.
This:

 <?php
echo '<pre>'.print_r($_FILES,1).'</pre>';
if(isset($_FILES['mp3_file']['name'])&& !empty($_FILES['mp3_file']['name']))
{
echo "yeah";
}

...is the only thing on the form, so there's no code prior to that. In other words, what you see above are the only "lines" on the entire page that I'm posting to.
I just now went back to the original form and I deleted all the fields except for the mp3 field so it looks like what you see below.

And I get the same result: Nothing.



<?php
session_start();
if (!isset ($_SESSION['sv_email'])) {               
header("Location:contestants_login.php");exit();
}
$sv_email=$_SESSION['sv_email'];
include("carter.inc"); 
$cxn = mysqli_connect($host,$user,$password,$database)or die ("couldn't connect to server");
$query = "select * from registration where email = '$sv_email'";
$result = mysqli_query($cxn, $query);

if(!$result) {$error = mysqli_errno($cxn).': '.mysqli_error($cxn);
die($error);
}
$row = mysqli_fetch_assoc($result);
extract($row);
$contestant_id = $id;
$contestant_radio_id = $radio_id;
$bio_text=$bio;
$contestant_first_name = $first_name;
$contestant_last_name = $last_name;
$contestant_primary = $primary_instrument;
$contestant_secondary = $secondary_instrument;
$contestant_stage_name = $stage_name;
$contestant_radio_name = $radio_name;
$contestant_artist_act = $artist_act;
$contestant_artist_music = $artist_music;
$contestant_security_question = $security_question;
$contestant_security_answer = $security_answer;
$the_password = $contestant_password;
$this_year = date("Y");
$contestant_lyrics = $lyrics;
$contestant_writer = $songwriting_contest;
$contestant_rules = $rules;
$contestant_mp3 = $mp3_file;
$contestant_year = $year;
$contestant_song_title = $song_title;
$contestant_hall = $fame;
$contestant_song_permission = $song_permission;



if(!empty($_GET['writer'])){
header("Location:contestants_editpage_write.php");
}

//this next block of code grabs the stage name or the first name of the contestant, depending if they have a stage name and determines whether or not there's an "s" at the end of the name so it can document that correctly
if(empty($contestant_stage_name)){
$display_name = $first_name;
}
else
{
$display_name = $contestant_stage_name;
}

$rest = substr("$display_name", -1);
if($rest=="s"){
$sweet_name = $display_name."'";
}
else
{
$sweet_name = $display_name."'s";
}

if(!empty($contestant_writer) AND $contestant_writer<> "0000-00-00"){
$songwriting_link = "contestants_editpage.php";
$songwriting=1;
}
else
{
$songwriting=0;
$songwriter_competitor=0;
$songwriting_link = "songwriting_intro.php?id=$contestant_id";
}

if($songwriting>0){
require_once('songwriting_admin.php');
require_once('songwriting_receipt.php');
require_once('songwriting_calendar.php');
require_once('songwriting_datecheck.php');
}

require_once('header.php');

?>

<body>
<table width=100% cellspacing="0" cellpadding="0">
<tr>
<td align="center" class="background">
	<table width="1000" cellspacing="0" cellpadding="0" border="0">
	<tr>
	<td><IMG SRC="images/spacer.gif" width="50" height="32">
	</td>
	<td><?php require_once('login_form.php'); ?></td>
	</tr>
	<tr>
	<td align="center" colspan="2">
	<?php require_once('flash_header.php'); ?>
	</td>
	</tr>
	<tr>
	<td colspan="2">&nbsp;<BR>
	</td>
	</tr>
	<tr>
	<td><IMG SRC="images/spacer.gif" width="50" height="32">
	</td>
	<td width="950" background="images/spacer.gif" width="950" width="32">
	<!- here's where you content goes, but you have to offset it a bit in order to accommodate the guitar that's technically hanging over the edge ->
		<table width="950" cellspacing="0" cellpadding="0">
		<tr>
		<!- here's where you've got your first column of info - this is your text ->
		<td width="592" valign="top">
			<?php require_once('contestant_menu.php'); ?>
			<!- here's all your content ->
			<td class="standard">&nbsp;<BR>
			Hello, <?php echo "$contestant_first_name"; ?>!
			<P>
			To make any changes to your Profile, simply alter the fields as you see them below, then click on "Update Page" at the very bottom of the page.
			<P>
			If you have any questions, contact <A HREF="Contact.php" class="body">SPI</a>.
			<P>
			Thanks!
			</td>
			</tr>
			<tr>
			<!-good ->
			
			<td>&nbsp;<BR>
				<table border="0">								
				<?php
				// this verbiage only shows up if the user is looking at their edit page without having first looked at the songwriting_intro.php page
				if($contestant_writer=="0000-00-00"){
				?>
				<tr>
				<td colspan="2">
				<div align="center"><b>If you're interested in competing in the Country Showdown Songwriting Competition, click <A HREF="songwriting_intro.php" class="body"><b>here</b></a></b>.
				</div>&nbsp;	<BR>
				</td>
				</tr>
				<?php
				}
				?>
				<?php
				// this verbiage only shows up if the user is looking at their edit page without having first looked at the songwriting_intro.php page
				if($contestant_rules=="0000-00-00"){
				?>
				<tr>
				<td colspan="2">
				<font size="1"><b>If you're interested in competing in the Country Showdown , click <A HREF="contestants_editpage_show.php" class="body"><font size="1"><b>here</b></font></a></b>.
				</td>
				</tr>
				<?php
				}
				?>
				<form enctype="multipart/form-data" action="contestants_edit_execute_test.php" method="POST">	
				
				
				<tr>
				<td class="standard">
				mp3
				</td>
				<td>
				<input name="mp3_file" type="file" size="37">
				</td>
				</tr>
				<tr>												
				<td colspan="2" class="standard">						
				<font size="1"><b>Only original music please! No covers.</b></font>						
				</td>						
				</tr>
				
				
				<tr>
				<td colspan="3" align="center">
				<input type="image" src="images/update_page.jpg" border="0" name="submit"></form>
				</td>
				</tr>
				
				<tr>
				<td colspan="2">
				&nbsp;<BR>
				</td>
				</tr>
				
				<tr>
				<td style="width: 100%; height: 100%; vertical-align: top; border: solid 1px white;" colspan="2"> 
				If you're uploading an mp3 file, understand that it can take a while. So be sure you hit "Submit" only once and then wait. Your file is being uploaded, but it can take up to 
				5 minutes depending on the size of the file and your connection speed.
				</td>
				</tr>
				<tr>
				<td colspan="2">
				&nbsp;<BR>
				</td>
				</tr>
				</table>
			</td>
			</tr>
			</table>
		</td>
		<td>
		<IMG SRC="images/spacer.gif" width="36" height="32">
		</td>
		<td width="302" valign="top"><!- this batch of code houses the contestant's stats, jukebox, calendar etc. -> 
		<?php require_once('contestant_column.php'); ?>
		</td>
		</tr>
		</table>
	</td>
	</tr>
	<?php require_once('footer.php'); ?>
	</table>
</td>
</tr>
</table>

</body>
</html>

Open in new window

Weird,
see if this simple test script works for you:

<?php 
if ($_POST) {
	echo '<pre>'.print_r($_POST,1).'</pre>';
	echo '<pre>'.print_r($_FILES,1).'</pre>';
}
?>
<form enctype="multipart/form-data" action="" method="POST">
<input name="mp3_file" type="file" size="37">
<input type="submit" border="0" name="submit" value="Submit">
</form>

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Roads' solution worked, but I'm still not there and it merits another question which you can see at https://www.experts-exchange.com/questions/26970232/Why-does-this-if-statement-not-work.html

In the interim, while I'm giving Roads_Roads the lion's share of the points, Rik I want to acknowledge your time. I do appreciate it, friend!