Bruce Gust
asked on
multipart form and hidden fields
I have a multipart form that works fine as long as I'm not using it to upload a picture or an mp3. The moment that I do attempt to upload an mp3, the hidden fields on that form seem to be ignored by the code that follows.
Bottom line: I've got a select statement that looks like this:
$vivian = "select * from registration where id = '$_POST[contestant_id]'";
$vivian_query = mysqli_query($cxn, $vivian)
or die ("Couldn't execute query.");
$vivian_row=mysqli_fetch_a ssoc($vivi an_query);
//you're getting an error here. Check to see if you're getting the contestant's id
extract($vivian_row);
The $_POST[contestant_id] variable is a hidden field that shows up fine when you're not trying to upload an mp3. When you do have that kind of data in the form, the page fails because it doesn't see the $_POST[contestant_id] value.
Why? And, how can I fix it?
Bottom line: I've got a select statement that looks like this:
$vivian = "select * from registration where id = '$_POST[contestant_id]'";
$vivian_query = mysqli_query($cxn, $vivian)
or die ("Couldn't execute query.");
$vivian_row=mysqli_fetch_a
//you're getting an error here. Check to see if you're getting the contestant's id
extract($vivian_row);
The $_POST[contestant_id] variable is a hidden field that shows up fine when you're not trying to upload an mp3. When you do have that kind of data in the form, the page fails because it doesn't see the $_POST[contestant_id] value.
Why? And, how can I fix it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
...and here's the mp3 script.
One thing that I will say: It may very well be that the reason I wasn't "seeing" the contestant_id is because the script was timing out. Since my last post, I was able to figure out that things were working fine as long as the uploaded file was less than 10MB. However, since I'm still chewing on this, if you could look at what I've got and see if there's something flawed, I would appreciate it.
Thanks!
One thing that I will say: It may very well be that the reason I wasn't "seeing" the contestant_id is because the script was timing out. Since my last post, I was able to figure out that things were working fine as long as the uploaded file was less than 10MB. However, since I'm still chewing on this, if you could look at what I've got and see if there's something flawed, I would appreciate it.
Thanks!
<?php
if(isset($_FILES['mp3_file']['name'])&& !empty($_FILES['mp3_file']['name']))
{
//checking here to see if contestant is currently participating in Songwriting Competition
$poppy = "select * from registration where id = '$_POST[contestant_id]'";
$poppy_query = mysqli_query($cxn, $poppy)
or die ("Couldn't execute query.");
$poppy_row = mysqli_fetch_assoc($poppy_query);
extract($poppy_row);
$mp3_today = date("Y-m-d");
$artist_songwriting_date = $songwriting_contest;
if($artist_songwriting_date <> "0000-00-00"){
//this contestant has declared that they want to be in the Songwriting Competition, now we have to find out if they're participating in contest currently underway
$contest = "select * from songwriting_contest where start_date <= '$mp3_today' ORDER by start_date ASC LIMIT 1";
$contest_query = mysqli_query($cxn, $contest)
or die ("Couldnt' execute query.");
$contest_count = mysqli_num_rows($contest_query);
if($contest_count >0){
//we've just determined that there is a contest currently underway with the above script, now we look to see if the start date for this particular contest is greater than the date the contestant entered. If it is, they're trying to adjust their song in the middle of the competition and they can't do that
$contest_row = mysqli_fetch_assoc($contest_query)
or die("Couldn't execute query.");
extract($contest_row);
$this_start_date = $start_date;
//now we post the question
if($artist_songwriting_date<=$this_start_date){
header("Location:songwriting_mp3_prohibited.php");
exit();
}
}
}
//end of Songwriting Competition code
$filecheck = basename($_FILES['mp3_file']['name']);
// this will return whatever is past the final . in the file name
$ext = strtolower(substr($filecheck, strrpos($filecheck, '.') + 1));
// check that the file extention is "mp3"
if (strtolower($ext) == 'mp3') {
//here is where you're uploading the mp3 file based on the fact that the file type is, indeed, an mp3
$userfile_name = (isset ($_FILES['mp3_file']['name']) ? $_FILES['mp3_file']['name'] : '');
if(!$_POST['originals']=="Y"){
header("Location: mp3_agreement.php");
exit();
}
if($_POST['song_title']==""){
header("Location: mp3_songtitle.php");
exit();
}
$filename = explode ('\\.', $userfile_name);
$good_ext = false;
$file_ext = '';
if (strcmp (substr ($userfile_name, 0 - 4, 1), '.') === 0)
{
$good_ext = true;
$file_ext = substr ($userfile_name, 0 - 3);
}
if (!$good_ext)
{
if (strcasecmp (substr ($userfile_name, 0 - 5, 1), '.') === 0)
{
$good_ext = true;
$file_ext = substr ($userfile_name, 0 - 4);
}
}
if (!$good_ext)
{
if (strcasecmp (substr ($userfile_name, 0 - 3, 1), '.') === 0)
{
$good_ext = true;
$file_ext = substr ($userfile_name, 0 - 2);
}
}
$target = "mp3/";
$target = $target . $_POST['contestant_id'].'.'.$file_ext;
if(!move_uploaded_file($_FILES['mp3_file']['tmp_name'], $target)) {
header("Location: mp3_noupload.php");
exit();
}
else
{
$song_title_clean = mysqli_real_escape_string($cxn, $_POST['song_title']);
$TodaysDate = date("Y-m-d");
$audio_file = "mp3";
$url =$_POST['contestant_id'].'.'.$audio_file;
$query_mp3 = "UPDATE registration SET mp3_file='$url',
song_title='$song_title_clean',
song_permission = '$TodaysDate'
WHERE id = '$_POST[contestant_id]'";
$mp3_exe = mysqli_query($cxn, $query_mp3);
if(!$mp3_exe) {
$error = mysqli_errno($cxn).': '.mysqli_error($cxn);
die($error);
}
}
}
else
{
header("Location:mp3_badfile.php");
exit();
}
}
?>
ASKER
jagadishdulal, in light of the lack of activity, I'm going to go ahead and award you the points for taking the time to weigh in.
The problem turned out to be the limits on what my server was allowing in terms of the size of the file being uploaded. Once I adjusted that, everything worked just fine.
Thanks for your input!
The problem turned out to be the limits on what my server was allowing in terms of the size of the file being uploaded. Once I adjusted that, everything worked just fine.
Thanks for your input!
ASKER
Open in new window