woodsonoversoul Posted December 31, 2008 Share Posted December 31, 2008 Alright guys, I've got an multi-file upload for which calls itself an passes itself certain variables. The problem is the variables aren't passing. Can anyone see why this: <form enctype="multipart/form-data" action="upload_script_ver2.php" method="post"> <?php //create hidden values to be passed to the next page echo "<input type =\"hidden\" name =\"band\" value =\"" . $band . "\" />"; echo "<input type =\"hidden\" name =\"year\" value =\"" . $year . "\" />"; echo "<input type =\"hidden\" name =\"month\" value =\"" . $month . "\" />"; echo "<input type =\"hidden\" name =\"day\" value =\"" . $day . "\" />"; echo "<input type =\"hidden\" name =\"setOne\" value =\"" . $setOne . "\" />"; echo "<input type =\"hidden\" name =\"setTwo\" value =\"" . $setTwo . "\" />"; echo "<input type =\"hidden\" name =\"encore\" value =\"" . $encore . "\" />"; //use a for loop to produce multiple upload boxes for($i = 0; $i < (count($set_one) + count($set_Two) + count($encore)); $i++){ ?> <input type ="hidden" name = "MAX_FILE_SIZE" value = "209715200" /> <fieldset><legend>Select a mp3 to upload:</legend> <?php //find and echo file/song info //first, find out which set it's in if($i < count($set_one)){ $set_num = '1'; $temp_set_array = $set_one; $count = $i; } if(($i >= count($set_one)) && ($i < (count($set_one) + count($set_Two)))){ $set_num = '2'; $temp_set_array = $set_Two; $count = $i - count($set_one); } if($i >= (count($set_one) + count($set_Two))){ $set_num = 'e'; $temp_set_array = $encore; $count = $i - count($set_one) - count($set_Two); } echo $band . " : " . $date . " : " . $temp_set_array[$count][2]; ?> <p><b>file:</b><input type="file" name ="upload[]" /></p> </fieldset> <?php //end for loop } ?> <div align="center"><input type="submit" name="submit" value="Submit" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> is not received by this: if($_POST && $_POST['submit'] == 'Submit'){ $band = $_POST['band']; $year = $_POST['year']; $month = $_POST['month']; $day = $_POST['day']; $date = create_date($year, $month, $day); $setOne = $_POST['setOne']; $set_Two = $_POST['setTwo']; $encore = $_POST['encore']; } else{ //If not, assign other variables $year = $_POST['year']; $month = $_POST['month']; $day = $_POST['day']; $date = create_date($year, $month, $day); $setOne = $_POST['setOne']; $set_Two = $_POST['setTwo']; $encore = $_POST['encore']; } ??? Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/ Share on other sites More sharing options...
.josh Posted December 31, 2008 Share Posted December 31, 2008 Are you talking about the form not populating the posted vars? Is that 2nd code above the first code in the script? Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-726725 Share on other sites More sharing options...
woodsonoversoul Posted December 31, 2008 Author Share Posted December 31, 2008 The form is at the end of a long script, and yes, below the variable assignments. They're all recieved from the original calling page, but not passed on when the page calls itself... Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-726727 Share on other sites More sharing options...
suzzane2020 Posted December 31, 2008 Share Posted December 31, 2008 I guess its this part: if($_POST && $_POST['submit'] == 'Submit'){ it should be if (($_POST)&&($_POST['submit']=='Submit')) { } Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-726728 Share on other sites More sharing options...
woodsonoversoul Posted December 31, 2008 Author Share Posted December 31, 2008 Thanks Suzzane2020, but no change Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-726731 Share on other sites More sharing options...
suzzane2020 Posted December 31, 2008 Share Posted December 31, 2008 check if its geting in the if loop (im sure u wud have done that) and if it is just try changing the way the values are passed.eg: <input type="hidden" name="name" value="<?php echo $value;?>"> echo them in the elements. I had a similar problem before. Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-726732 Share on other sites More sharing options...
suzzane2020 Posted December 31, 2008 Share Posted December 31, 2008 On second thought. nope. what ur doing is absolutely fine. Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-726735 Share on other sites More sharing options...
woodsonoversoul Posted December 31, 2008 Author Share Posted December 31, 2008 The if loop doesn't extend that far, and I know sometimes little things make a big difference, but I feel that my syntax around those variables is correct. Here's the whole code, see anything else? <?php #File uploading script ////////////////////////////////////////////////////////////////// //File: upload_script.php //Author: Daniel Woodson (w/ help from gevans from phpfreaks.org) //Purpose: Upload multiple files //Last update: 12-10-08 //Comment: Working on renaming uploaded files ////////////////////////////////////////////////////////////////// ////////////////functions//////////////////// function create_date($year, $month, $day){ //function combines year, month, and day into a yyyy-mm-dd format if($month < 10){ $month = '0' . $month; } if($day < 10){ $day = '0' . $day; } return $year . "-" . $month . "-" . $day; }//end create_date() function create_song_array($set, $unique_show_id, $set_num) { /*function takes in show.set object, splits that object into an array, and then makes it multidiminsional. It then creates and assigns song ids to the first row of the array and song titles to the third row */ //split the object($set) into a dummy array based on ',' and '>', using perl-type regex $dummy_array = preg_split("/(,|>)/", $set); //use the trim() function to remove leading/trailing white spaces for($i=0;$i<count($dummy_array);$i++){ $dummy_array[$i] = trim($dummy_array[$i]); } //then create the real array as a copy of dummy array $song_array = array(count($dummy_array)); //make the real array multidiminsional and create eight //rows to hold the song's various properties for($i = 0; $i < count($dummy_array); $i++){ $song_array[$i] = array(; } //assign song title, set_one_songs[2] = dummy_array[1] for($m = 0; $m < count($dummy_array); $m++){ $song_array[$m][2] = $dummy_array[$m]; } //assign unique song ids (###NOTE: $n+1 should return a value which is in a 2 digit form###) for($n = 0; $n < count($dummy_array); $n++) { $song_array[$n][0] = $unique_show_id . "s" . $set_num . "s"; if($n < 10){ $song_array[$n][0] = $song_array[$n][0] . '0' . ($n+1); } else{ $song_array[$n][0] = $song_array[$n][0] . ($n+1); } } //return newly created array return $song_array; }//create_song_array() function showIdCreator($band, $date) { /*this function takes in the user inputed band name and show date. It then produces an abbreviation from the band name. It then returns this abbreviation combined with the show date to create the show id*/ //variable declarations $abb;//store the abbreviated band name //convert the band name to lower case for easier comparison $band = strtolower($band); //set abbreviation based on band name switch($band) { case "widespread panic" : $abb = "wsp"; break; case "grateful dead" : $abb = "gd"; break; case "phish" : $abb = "ph"; break; case "ryan adams" : $abb = "ra"; break; default: $abb = "unknown"; break; } //return a combination of the band name abbreviation and the show date return $abb . $date; }//end showIdCreator() function printHead(){ echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>File Uploader</title> <style type="text/css" title ="text/css" media="all"> .error { font-weight: bold; color: #C00 } </style> </head> <body>'; }//end printHead() ////////////////end of functions//////////////////// ////////////////begin lead-in php/////////////////// //turn on error reporting ini_set('display_errors', 'On'); error_reporting(E_ALL | E_STRICT); //print html header printHead(); #print html head //Initailize and assign values to starter variables. //If the page is calling itself, assign certain variables if(($_POST)&&($_POST['submit']=='Submit')){ $band = $_POST['band']; $year = $_POST['year']; $month = $_POST['month']; $day = $_POST['day']; $date = create_date($year, $month, $day); $setOne = $_POST['setOne']; $set_Two = $_POST['setTwo']; $encore = $_POST['encore']; } else{ //If not, assign other variables $year = $_POST['year']; $month = $_POST['month']; $day = $_POST['day']; $date = create_date($year, $month, $day); $setOne = $_POST['setOne']; $setTwo = $_POST['setTwo']; $encore = $_POST['encore']; } //create a unique show id $unique_show_id = showIdCreator($band, $date); //create an array of songs based on set on and save it to an array of the same name $set_one = create_song_array($setOne, $unique_show_id, "1"); $set_Two = create_song_array($setTwo, $unique_show_id, "2"); $encore = create_song_array($encore, $unique_show_id, "e"); //check to see if file has been submitted if(isset($_POST['submitted'])){ //connect to database $con = mysql_connect("***", ""***,""); if (!$con){ die('Could not connect: ' . mysql_error()); } mysql_select_db("musicneverstopped", $con); //end connecting to database //start a loop to move through all the files for($i = 0; $i < count($_FILES['upload']['name']); $i++){ //debug - show all pertinate file info /*echo "<pre>"; print_r($_FILES); echo "</pre>";*/ //create an array of allowed types (###NOTE: need MIME type for Flac###) $allowed = array('audio/mpeg'); //now evaluate current file //check to see if current file's type is in the array of allowed types if(in_array($_FILES['upload']['type'][$i], $allowed)){ //If True, move the file to new location //first, fin out which set it's in if($i < count($set_one)){ $set_num = '1'; $temp_set_array = $set_one; } if($i > count($set_one) && $i < (count($set_one) + count($set_Two))){ $set_num = '2'; $temp_set_array = $set_Two; } if($i > (count($set_one) + count($set_Two))){ $set_num = 'e'; $temp_set_array = $encore; } //now find here it's at in the set if(($i - count($set_one)) < 0){ $set_position = $i + 1; } if(($i - count($set_one) + count($set_Two)) < 0){ $set_position = $i - count($set_one) + 1; } else{$set_position = ($i - (count($set_one) + count($set_Two)) + 1);} //create a variable to hold some basic information $song_id = $temp_set_array[$i][0]; $file_location = "***" . $temp_set_array[$i][0] . ".mp3"; $song_name = $temp_set_array[$i][2]; if(move_uploaded_file($_FILES['upload']['tmp_name'][$i], "/***/" . $temp_set_array[$i][0] . ".mp3")){ //once uploaded, send information to database $sql= "INSERT INTO songs (unique_song_id, file_location, artist, date, name, set, set_position) VALUES('$song_id','$file_location','$band', '$date', '$song_name', '$set_num, $set_position)"; if (!mysql_query($sql,$con)){ die('Error: ' . mysql_error()); } echo "1 record added"; echo '<p><em>The file has been uploaded!</em></p>'; //Delete file if if still exist if(file_exists($_FILES['upload']['tmp_name'][$i]) && is_files($_FILES['upload']['tmp_name'][$i])){ unlink($_FILES['upload']['tmp_name'][$i]); } } else { if($_FILES['upload']['error'][$i] > 0){ echo '<p class="error">The file could not be uploaded because: <strong>'; //print message based on error switch($_FILES['upload']['error'][$i]){ case 1: print 'The file exceeds the upload_max_filesize settiing in php.ini'; break; case 2: print 'The file exceeds the MAX_FILE_SIZE setting in the html form'; break; case 3: print 'The file was only partially uploaded'; break; case 4: print 'No file was uploaded'; break; case 6: print 'No temporary folder was available'; break; case 7: print 'Unable to write to the disk'; break; case 8: print 'File upload was stopped'; break; default: print 'A system error occured'; break; }//end of switch print '</strong></p>'; }//end of error if } } else {//invaild type echo '<p class="error">Error: Wrong filetype. Must be an mp3</p>'; }//end else }//end for loop mysql_close($con);//close mysql connection }//end isset ////////////////begin actual page/////////////////// //display show information echo "The band is: " . $band . "<br>"; echo "The show date is: " . $date . "<br>"; echo "Unique show id: " . $unique_show_id . "<br><br>"; //end original php section ?> <form enctype="multipart/form-data" action="upload_script_ver2.php" method="post"> <?php //create hidden values to be passed to the next page echo "<input type =\"hidden\" name =\"band\" value =\"" . $band . "\" />"; echo "<input type =\"hidden\" name =\"year\" value =\"" . $year . "\" />"; echo "<input type =\"hidden\" name =\"month\" value =\"" . $month . "\" />"; echo "<input type =\"hidden\" name =\"day\" value =\"" . $day . "\" />"; echo "<input type =\"hidden\" name =\"setOne\" value =\"" . $setOne . "\" />"; echo "<input type =\"hidden\" name =\"setTwo\" value =\"" . $setTwo . "\" />"; echo "<input type =\"hidden\" name =\"encore\" value =\"" . $encore . "\" />"; //use a for loop to produce multiple upload boxes for($i = 0; $i < (count($set_one) + count($set_Two) + count($encore)); $i++){ ?> <input type ="hidden" name = "MAX_FILE_SIZE" value = "209715200" /> <fieldset><legend>Select a mp3 to upload:</legend> <?php //find and echo file/song info //first, find out which set it's in if($i < count($set_one)){ $set_num = '1'; $temp_set_array = $set_one; $count = $i; } if(($i >= count($set_one)) && ($i < (count($set_one) + count($set_Two)))){ $set_num = '2'; $temp_set_array = $set_Two; $count = $i - count($set_one); } if($i >= (count($set_one) + count($set_Two))){ $set_num = 'e'; $temp_set_array = $encore; $count = $i - count($set_one) - count($set_Two); } echo $band . " : " . $date . " : " . $temp_set_array[$count][2]; ?> <p><b>file:</b><input type="file" name ="upload[]" /></p> </fieldset> <?php //end for loop } ?> <div align="center"><input type="submit" name="submit" value="Submit" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-726737 Share on other sites More sharing options...
suzzane2020 Posted December 31, 2008 Share Posted December 31, 2008 Which form are you using to get the other variables if $_POST is not set? Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-726738 Share on other sites More sharing options...
suzzane2020 Posted December 31, 2008 Share Posted December 31, 2008 where are the variable values assigned?. I dont see them in the code. Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-726739 Share on other sites More sharing options...
woodsonoversoul Posted December 31, 2008 Author Share Posted December 31, 2008 I'm $_POSTing them from another form <html> <head> <title>Music Archiver</title> </head> <body> <form name="archive_input" action="upload_script_ver2.php" method="post"> <table> <tr><td><b>Enter Show Information:</b></td></tr> <tr> <td>Band:</td> <td><input type="text" name="band"></td> </tr> <tr> <td>Date:</td> <td><select name="year"> <option>Year</option> <option>2009</option> <option>2008</option> <option>2007</option> <option>2006</option> <option>2005</option> <option>2004</option> <option>2003</option> <option>2002</option> <option>2001</option> <option>2000</option> <option>1999</option> <option>1998</option> <option>1997</option> <option>1996</option> <option>1995</option> <option>1994</option> <option>1993</option> <option>1992</option> <option>1991</option> <option>1990</option> <option>1989</option> <option>1988</option> <option>1987</option> </select> <select name="month"> <option>Month</option> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> <option>6</option> <option>7</option> <option>8</option> <option>9</option> <option>10</option> <option>11</option> <option>12</option> </select> <select name="day"> <option>Day</option> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> <option>6</option> <option>7</option> <option>8</option> <option>9</option> <option>10</option> <option>11</option> <option>12</option> <option>13</option> <option>14</option> <option>15</option> <option>16</option> <option>17</option> <option>18</option> <option>19</option> <option>20</option> <option>21</option> <option>22</option> <option>23</option> <option>24</option> <option>25</option> <option>26</option> <option>27</option> <option>28</option> <option>29</option> <option>30</option> <option>31</option> </select></td> </tr> <tr> <td>Location:</td> <td><input type="text" name="loc"></td> </tr> <tr> <td>Set 1:</td> <td><textarea name="setOne" rows="4" cols="45"></textarea></td> </tr> <tr> <td>Set 2:</td> <td><textarea name="setTwo" rows="4" cols="45"></textarea></td> </tr> <tr> <td>Encore:</td> <td><input type="text" name="encore" size="39"></td> </tr> <tr><td></td> <td><input type="submit" value="Archive"> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-726744 Share on other sites More sharing options...
suzzane2020 Posted December 31, 2008 Share Posted December 31, 2008 Did you check if the values are available in the second page? btw the band value is not being called in the else part else{ //If not, assign other variables $year = $_POST['year']; $month = $_POST['month']; $day = $_POST['day']; $date = create_date($year, $month, $day); $setOne = $_POST['setOne']; $set_Two = $_POST['setTwo']; $encore = $_POST['encore']; } Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-726747 Share on other sites More sharing options...
woodsonoversoul Posted December 31, 2008 Author Share Posted December 31, 2008 yeah, I know about the $band thing, but that's the only way it would work. I;m guessing the variables aren't available on the second page as I'm getting errors every time the page calls them - Notice: Undefined index: year in /opt/lampp/htdocs/MSNTesting/upload_script_ver2.php on line 146 Notice: Undefined index: month in /opt/lampp/htdocs/MSNTesting/upload_script_ver2.php on line 147 Notice: Undefined index: day in /opt/lampp/htdocs/MSNTesting/upload_script_ver2.php on line 148 Notice: Undefined index: setOne in /opt/lampp/htdocs/MSNTesting/upload_script_ver2.php on line 150 Notice: Undefined index: setTwo in /opt/lampp/htdocs/MSNTesting/upload_script_ver2.php on line 151 Notice: Undefined index: encore in /opt/lampp/htdocs/MSNTesting/upload_script_ver2.php on line 152 Notice: Undefined variable: band in /opt/lampp/htdocs/MSNTesting/upload_script_ver2.php on line 156 Notice: Undefined variable: band in /opt/lampp/htdocs/MSNTesting/upload_script_ver2.php on line 274 The band is: The show date is: -0-0 Unique show id: unknown-0-0 Notice: Undefined variable: band in /opt/lampp/htdocs/MSNTesting/upload_script_ver2.php on line 284 Notice: Undefined index: setOne in /opt/lampp/htdocs/MSNTesting/upload_script_ver2.php on line 288 Select a mp3 to upload: Notice: Undefined variable: band in /opt/lampp/htdocs/MSNTesting/upload_script_ver2.php on line 319 : -0-0 : file: Select a mp3 to upload: Notice: Undefined variable: band in /opt/lampp/htdocs/MSNTesting/upload_script_ver2.php on line 319 : -0-0 : file: Select a mp3 to upload: Notice: Undefined variable: band in /opt/lampp/htdocs/MSNTesting/upload_script_ver2.php on line 319 : -0-0 : file: Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-726749 Share on other sites More sharing options...
suzzane2020 Posted December 31, 2008 Share Posted December 31, 2008 What exactly is this section of code supposed to do? //first, find out which set it's in if($i < count($setOne)){ $set_num = '1'; $temp_set_array = $setOne; $count = $i; } if(($i >= count($setOne)) && ($i < (count($setOne) + count($set_Two)))){ $set_num = '2'; $temp_set_array = $set_Two; $count = $i - count($setOne); } if($i >= (count($setOne) + count($set_Two))){ $set_num = 'e'; $temp_set_array = $encore; $count = $i - count($setOne) - count($set_Two); } If you are trying to display the file paths , wont it be a better option to allow the user to select the file they want to upload? you can provide an option to upload multiple files at a time. Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-726756 Share on other sites More sharing options...
kenrbnsn Posted December 31, 2008 Share Posted December 31, 2008 The submit button doesn't have a name, so the if statement is never true. Change <td><input type="submit" value="Archive"> to <td><input type="submit" value="Archive" name="submit"> Also the value of the submit button is "Archive", not "Submit". Ken Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-726757 Share on other sites More sharing options...
woodsonoversoul Posted December 31, 2008 Author Share Posted December 31, 2008 I commented out the if statement so it checks for the variables everytime (like it was anyway, the if statement was redundant) and it still doesn't pass any variables when it calls itself... new code: <?php #File uploading script ////////////////////////////////////////////////////////////////// //File: upload_script.php //Author: Daniel Woodson (w/ help from gevans from phpfreaks.org) //Purpose: Upload multiple files //Last update: 12-10-08 //Comment: Working on renaming uploaded files ////////////////////////////////////////////////////////////////// ////////////////functions//////////////////// function create_date($year, $month, $day){ //function combines year, month, and day into a yyyy-mm-dd format if($month < 10){ $month = '0' . $month; } if($day < 10){ $day = '0' . $day; } return $year . "-" . $month . "-" . $day; }//end create_date() function create_song_array($set, $unique_show_id, $set_num) { /*function takes in show.set object, splits that object into an array, and then makes it multidiminsional. It then creates and assigns song ids to the first row of the array and song titles to the third row */ //split the object($set) into a dummy array based on ',' and '>', using perl-type regex $dummy_array = preg_split("/(,|>)/", $set); //use the trim() function to remove leading/trailing white spaces for($i=0;$i<count($dummy_array);$i++){ $dummy_array[$i] = trim($dummy_array[$i]); } //then create the real array as a copy of dummy array $song_array = array(count($dummy_array)); //make the real array multidiminsional and create eight //rows to hold the song's various properties for($i = 0; $i < count($dummy_array); $i++){ $song_array[$i] = array(; } //assign song title, set_one_songs[2] = dummy_array[1] for($m = 0; $m < count($dummy_array); $m++){ $song_array[$m][2] = $dummy_array[$m]; } //assign unique song ids (###NOTE: $n+1 should return a value which is in a 2 digit form###) for($n = 0; $n < count($dummy_array); $n++) { $song_array[$n][0] = $unique_show_id . "s" . $set_num . "s"; if($n < 10){ $song_array[$n][0] = $song_array[$n][0] . '0' . ($n+1); } else{ $song_array[$n][0] = $song_array[$n][0] . ($n+1); } } //return newly created array return $song_array; }//create_song_array() function showIdCreator($band, $date) { /*this function takes in the user inputed band name and show date. It then produces an abbreviation from the band name. It then returns this abbreviation combined with the show date to create the show id*/ //variable declarations $abb;//store the abbreviated band name //convert the band name to lower case for easier comparison $band = strtolower($band); //set abbreviation based on band name switch($band) { case "widespread panic" : $abb = "wsp"; break; case "grateful dead" : $abb = "gd"; break; case "phish" : $abb = "ph"; break; case "ryan adams" : $abb = "ra"; break; default: $abb = "unknown"; break; } //return a combination of the band name abbreviation and the show date return $abb . $date; }//end showIdCreator() function printHead(){ echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>File Uploader</title> <style type="text/css" title ="text/css" media="all"> .error { font-weight: bold; color: #C00 } </style> </head> <body>'; }//end printHead() ////////////////end of functions//////////////////// ////////////////begin lead-in php/////////////////// //turn on error reporting ini_set('display_errors', 'On'); error_reporting(E_ALL | E_STRICT); //print html header printHead(); #print html head //Initailize and assign values to starter variables. //If the page is calling itself, assign certain variables /*if(($_POST)&&($_POST['submit']=='submit')){ $band = $_POST['band']; $year = $_POST['year']; $month = $_POST['month']; $day = $_POST['day']; $date = create_date($year, $month, $day); $setOne = $_POST['setOne']; $set_Two = $_POST['setTwo']; $encore = $_POST['encore']; } else{ *///If not, assign other variables $band = $_POST['band']; $year = $_POST['year']; $month = $_POST['month']; $day = $_POST['day']; $date = create_date($year, $month, $day); $setOne = $_POST['setOne']; $setTwo = $_POST['setTwo']; $encore = $_POST['encore']; //} //create a unique show id $unique_show_id = showIdCreator($band, $date); //create an array of songs based on set on and save it to an array of the same name $set_one = create_song_array($setOne, $unique_show_id, "1"); $set_Two = create_song_array($setTwo, $unique_show_id, "2"); $encore = create_song_array($encore, $unique_show_id, "e"); //check to see if file has been submitted if(isset($_POST['submitted'])){ //connect to database $con = mysql_connect("***","***",""); if (!$con){ die('Could not connect: ' . mysql_error()); } mysql_select_db("***", $con); //end connecting to database //start a loop to move through all the files for($i = 0; $i < count($_FILES['upload']['name']); $i++){ //debug - show all pertinate file info /*echo "<pre>"; print_r($_FILES); echo "</pre>";*/ //create an array of allowed types (###NOTE: need MIME type for Flac###) $allowed = array('audio/mpeg'); //now evaluate current file //check to see if current file's type is in the array of allowed types if(in_array($_FILES['upload']['type'][$i], $allowed)){ //If True, move the file to new location //first, fin out which set it's in if($i < count($set_one)){ $set_num = '1'; $temp_set_array = $set_one; } if($i > count($set_one) && $i < (count($set_one) + count($set_Two))){ $set_num = '2'; $temp_set_array = $set_Two; } if($i > (count($set_one) + count($set_Two))){ $set_num = 'e'; $temp_set_array = $encore; } //now find here it's at in the set if(($i - count($set_one)) < 0){ $set_position = $i + 1; } if(($i - count($set_one) + count($set_Two)) < 0){ $set_position = $i - count($set_one) + 1; } else{$set_position = ($i - (count($set_one) + count($set_Two)) + 1);} //create a variable to hold some basic information $song_id = $temp_set_array[$i][0]; $file_location = "/home/dan/MusicDataBase/" . $temp_set_array[$i][0] . ".mp3"; $song_name = $temp_set_array[$i][2]; if(move_uploaded_file($_FILES['upload']['tmp_name'][$i], "/home/dan/MusicDataBase/" . $temp_set_array[$i][0] . ".mp3")){ //once uploaded, send information to database $sql= "INSERT INTO songs (unique_song_id, file_location, artist, date, name, set, set_position) VALUES('$song_id','$file_location','$band', '$date','$song_name','$set_num','$set_position')"; if (!mysql_query($sql,$con)){ die('Error: ' . mysql_error()); } echo "1 record added"; echo '<p><em>The file has been uploaded!</em></p>'; //Delete file if if still exist if(file_exists($_FILES['upload']['tmp_name'][$i]) && is_files($_FILES['upload']['tmp_name'][$i])){ unlink($_FILES['upload']['tmp_name'][$i]); } } else { if($_FILES['upload']['error'][$i] > 0){ echo '<p class="error">The file could not be uploaded because: <strong>'; //print message based on error switch($_FILES['upload']['error'][$i]){ case 1: print 'The file exceeds the upload_max_filesize settiing in php.ini'; break; case 2: print 'The file exceeds the MAX_FILE_SIZE setting in the html form'; break; case 3: print 'The file was only partially uploaded'; break; case 4: print 'No file was uploaded'; break; case 6: print 'No temporary folder was available'; break; case 7: print 'Unable to write to the disk'; break; case 8: print 'File upload was stopped'; break; default: print 'A system error occured'; break; }//end of switch print '</strong></p>'; }//end of error if } } else {//invaild type echo '<p class="error">Error: Wrong filetype. Must be an mp3</p>'; }//end else }//end for loop mysql_close($con);//close mysql connection }//end isset ////////////////begin actual page/////////////////// //display show information echo "The band is: " . $band . "<br>"; echo "The show date is: " . $date . "<br>"; echo "Unique show id: " . $unique_show_id . "<br><br>"; //end original php section ?> <form enctype="multipart/form-data" action="upload_script_ver2.php" method="post"> <?php //create hidden values to be passed to the next page echo "<input type =\"hidden\" name =\"band\" value =\"" . $band . "\" />"; echo "<input type =\"hidden\" name =\"year\" value =\"" . $year . "\" />"; echo "<input type =\"hidden\" name =\"month\" value =\"" . $month . "\" />"; echo "<input type =\"hidden\" name =\"day\" value =\"" . $day . "\" />"; echo "<input type =\"hidden\" name =\"setOne\" value =\"" . $setOne . "\" />"; echo "<input type =\"hidden\" name =\"setTwo\" value =\"" . $setTwo . "\" />"; echo "<input type =\"hidden\" name =\"encore\" value =\"" . $encore . "\" />"; //use a for loop to produce multiple upload boxes for($i = 0; $i < (count($set_one) + count($set_Two) + count($encore)); $i++){ ?> <input type ="hidden" name = "MAX_FILE_SIZE" value = "209715200" /> <fieldset><legend>Select a mp3 to upload:</legend> <?php //find and echo file/song info //first, find out which set it's in if($i < count($set_one)){ $set_num = '1'; $temp_set_array = $set_one; $count = $i; } if(($i >= count($set_one)) && ($i < (count($set_one) + count($set_Two)))){ $set_num = '2'; $temp_set_array = $set_Two; $count = $i - count($set_one); } if($i >= (count($set_one) + count($set_Two))){ $set_num = 'e'; $temp_set_array = $encore; $count = $i - count($set_one) - count($set_Two); } echo $band . " : " . $date . " : " . $temp_set_array[$count][2]; ?> <p><b>file:</b><input type="file" name ="upload[]" /></p> </fieldset> <?php //end for loop } ?> <div align="center"><input type="submit" name="submit" value="submit" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> </body> </html> @kenrbnsn- it's reading the variables fine from the calling page, it's when the uploading page calls itself Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-727283 Share on other sites More sharing options...
kenrbnsn Posted January 1, 2009 Share Posted January 1, 2009 At the start of the script put <?php echo '<pre>' . print_r($_POST,true) . '</pre>'; ?> and see whether anything is displayed after you submit the form. Ken Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-727304 Share on other sites More sharing options...
woodsonoversoul Posted January 1, 2009 Author Share Posted January 1, 2009 Thanks Ken. Nothing is displayed Array ( ) Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-727320 Share on other sites More sharing options...
woodsonoversoul Posted January 1, 2009 Author Share Posted January 1, 2009 That is, nothing is displayed when the page calls itself. When it's first called, everything displays properly... Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-727323 Share on other sites More sharing options...
kenrbnsn Posted January 1, 2009 Share Posted January 1, 2009 How is the page invoked the first time? How is it invoked the second time? Put <?php echo '<pre>' . print_r($_GET,true) . '</pre>'; ?> right before the other print_r. This will tell you whether you're using the wrong method in the form. Ken Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-727460 Share on other sites More sharing options...
woodsonoversoul Posted January 1, 2009 Author Share Posted January 1, 2009 Thanks Ken. I'll try that and post the results... Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-727571 Share on other sites More sharing options...
woodsonoversoul Posted January 2, 2009 Author Share Posted January 2, 2009 I don't get anything from that either Ken. I believe my from method is proper: <form enctype="multipart/form-data" name="upload_script_ver2.php" action="upload_script_ver2.php" method="post"> <?php //create hidden values to be passed to the next page echo "<input type =\"hidden\" name =\"band\" value =\"" . $band . "\" />"; echo "<input type =\"hidden\" name =\"year\" value =\"" . $year . "\" />"; echo "<input type =\"hidden\" name =\"month\" value =\"" . $month . "\" />"; echo "<input type =\"hidden\" name =\"day\" value =\"" . $day . "\" />"; echo "<input type =\"hidden\" name =\"setOne\" value =\"" . $setOne . "\" />"; echo "<input type =\"hidden\" name =\"setTwo\" value =\"" . $setTwo . "\" />"; echo "<input type =\"hidden\" name =\"encore\" value =\"" . $encore . "\" />"; but it keeps saying nothing is passed? Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-728157 Share on other sites More sharing options...
woodsonoversoul Posted January 2, 2009 Author Share Posted January 2, 2009 Alright, as an update; I've made the changes you've suggested along with a couple of my own (mostly tidying up code), but still no luck. Can anyone see why this: <?php #File uploading script ////////////////////////////////////////////////////////////////// //File: upload_script.php //Author: Daniel Woodson (w/ help from gevans from phpfreaks.org) //Purpose: Upload multiple files //Last update: 12-30-08 //Comment: Working on passing variables ////////////////////////////////////////////////////////////////// ////////////////functions//////////////////// function create_date($year, $month, $day){ //function combines year, month, and day into a yyyy-mm-dd format if($month < 10){ $month = '0' . $month; } if($day < 10){ $day = '0' . $day; } return $year . "-" . $month . "-" . $day; }//end create_date() function create_song_array($set, $unique_show_id, $set_num) { /*function takes in show.set object, splits that object into an array, and then makes it multidiminsional. It then creates and assigns song ids to the first row of the array and song titles to the third row */ //split the object($set) into a dummy array based on ',' and '>', using perl-type regex $dummy_array = preg_split("/(,|>)/", $set); //use the trim() function to remove leading/trailing white spaces for($i=0;$i<count($dummy_array);$i++){ $dummy_array[$i] = trim($dummy_array[$i]); } //then create the real array as a copy of dummy array $song_array = array(count($dummy_array)); //make the real array multidiminsional and create eight //rows to hold the song's various properties for($i = 0; $i < count($dummy_array); $i++){ $song_array[$i] = array(; } //assign song title, set_one_songs[2] = dummy_array[1] for($m = 0; $m < count($dummy_array); $m++){ $song_array[$m][2] = $dummy_array[$m]; } //assign unique song ids (###NOTE: $n+1 should return a value which is in a 2 digit form###) for($n = 0; $n < count($dummy_array); $n++) { $song_array[$n][0] = $unique_show_id . "s" . $set_num . "s"; if($n < 10){ $song_array[$n][0] = $song_array[$n][0] . '0' . ($n+1); } else{ $song_array[$n][0] = $song_array[$n][0] . ($n+1); } } //return newly created array return $song_array; }//create_song_array() function showIdCreator($band, $date) { /*this function takes in the user inputed band name and show date. It then produces an abbreviation from the band name. It then returns this abbreviation combined with the show date to create the show id*/ //variable declarations $abb;//store the abbreviated band name //convert the band name to lower case for easier comparison $band = strtolower($band); //set abbreviation based on band name switch($band) { case "widespread panic" : $abb = "wsp"; break; case "grateful dead" : $abb = "gd"; break; case "phish" : $abb = "ph"; break; case "ryan adams" : $abb = "ra"; break; default: $abb = "unknown"; break; } //return a combination of the band name abbreviation and the show date return $abb . $date; }//end showIdCreator() function printHead(){ echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>File Uploader</title> <style type="text/css" title ="text/css" media="all"> .error { font-weight: bold; color: #C00 } </style> </head> <body>'; }//end printHead() ////////////////end of functions//////////////////// ////////////////begin lead-in php/////////////////// //turn on error reporting ini_set('display_errors', 'On'); error_reporting(E_ALL | E_STRICT); //print html header printHead(); #print html head //Initailize and assign values to starter variables. //debug echo '<pre>' . print_r($_GET,true) . '</pre>'; echo '<pre>' . print_r($_POST,true) . '</pre>'; $band = $_POST['band']; $year = $_POST['year']; $month = $_POST['month']; $day = $_POST['day']; $date = create_date($year, $month, $day); $setOne = $_POST['setOne']; $setTwo = $_POST['setTwo']; $encore = $_POST['encore']; //} //create a unique show id $unique_show_id = showIdCreator($band, $date); //create an array of songs based on set on and save it to an array of the same name $set_one = create_song_array($setOne, $unique_show_id, "1"); $set_Two = create_song_array($setTwo, $unique_show_id, "2"); $encore = create_song_array($encore, $unique_show_id, "e"); //check to see if file has been submitted if(isset($_POST['submitted'])){ //connect to database $con = mysql_connect("***","***",""); if (!$con){ die('Could not connect: ' . mysql_error()); } mysql_select_db("***", $con); //end connecting to database //start a loop to move through all the files for($i = 0; $i < count($_FILES['upload']['name']); $i++){ //debug - show all pertinate file info /*echo "<pre>"; print_r($_FILES); echo "</pre>";*/ //create an array of allowed types (###NOTE: need MIME type for Flac###) $allowed = array('audio/mpeg'); //now evaluate current file //check to see if current file's type is in the array of allowed types if(in_array($_FILES['upload']['type'][$i], $allowed)){ //If True, move the file to new location //first, fin out which set it's in if($i < count($set_one)){ $set_num = '1'; $temp_set_array = $set_one; } if($i >= count($set_one) && $i < (count($set_one) + count($set_Two))){ $set_num = '2'; $temp_set_array = $set_Two; } if($i >= (count($set_one) + count($set_Two))){ $set_num = 'e'; $temp_set_array = $encore; } //now find where it's at in the set if(($i - count($set_one)) < 0){ $set_position = $i + 1; } if(($i - count($set_one) + count($set_Two)) < 0){ $set_position = $i - count($set_one) + 1; } else{$set_position = ($i - (count($set_one) + count($set_Two)) + 1);} //create a variable to hold some basic information $song_id = $temp_set_array[$i][0]; $file_location = "/home/dan/MusicDataBase/" . $temp_set_array[$i][0] . ".mp3"; $song_name = $temp_set_array[$i][2]; if(move_uploaded_file($_FILES['upload']['tmp_name'][$i], "/home/dan/MusicDataBase/" . $temp_set_array[$i][0] . ".mp3")){ //testing //mysql_query("INSERT INTO songs (unique_song_id, file_location, artist, date, name, set, set_position) //VALUES ('$song_id','$file_location','$band','$date','$song_name','$set_num','$set_position')"); //once uploaded, send information to database $sql= "INSERT INTO songs (unique_song_id, file_location, artist, date, name, set_num, set_position) VALUES('$song_id','$file_location','$band','$date','$song_name','$set_num','$set_position')"; if (!mysql_query($sql,$con)){ die('Error: ' . mysql_error()); } echo "1 record added"; echo '<p><em>The file has been uploaded!</em></p>'; //Delete file if if still exist if(file_exists($_FILES['upload']['tmp_name'][$i]) && is_files($_FILES['upload']['tmp_name'][$i])){ unlink($_FILES['upload']['tmp_name'][$i]); } } else { if($_FILES['upload']['error'][$i] > 0){ echo '<p class="error">The file could not be uploaded because: <strong>'; //print message based on error switch($_FILES['upload']['error'][$i]){ case 1: print 'The file exceeds the upload_max_filesize settiing in php.ini'; break; case 2: print 'The file exceeds the MAX_FILE_SIZE setting in the html form'; break; case 3: print 'The file was only partially uploaded'; break; case 4: print 'No file was uploaded'; break; case 6: print 'No temporary folder was available'; break; case 7: print 'Unable to write to the disk'; break; case 8: print 'File upload was stopped'; break; default: print 'A system error occured'; break; }//end of switch print '</strong></p>'; }//end of error if } } else {//invaild type echo '<p class="error">Error: Wrong filetype. Must be an mp3</p>'; }//end else }//end for loop mysql_close($con);//close mysql connection }//end isset ////////////////begin actual page/////////////////// //display show information echo "The band is: " . $band . "<br>"; echo "The show date is: " . $date . "<br>"; echo "Unique show id: " . $unique_show_id . "<br><br>"; //begin form header echo "<form enctype=\"multipart/form-data\" name=\"upload_script_ver2.php\" action=\"upload_script_ver2.php\" method=\"post\">"; //create hidden values to be passed to the next page echo "<input type =\"hidden\" name =\"band\" value =\"" . $band . "\" />"; echo "<input type =\"hidden\" name =\"year\" value =\"" . $year . "\" />"; echo "<input type =\"hidden\" name =\"month\" value =\"" . $month . "\" />"; echo "<input type =\"hidden\" name =\"day\" value =\"" . $day . "\" />"; echo "<input type =\"hidden\" name =\"setOne\" value =\"" . $setOne . "\" />"; echo "<input type =\"hidden\" name =\"setTwo\" value =\"" . $setTwo . "\" />"; echo "<input type =\"hidden\" name =\"encore\" value =\"" . $encore . "\" />"; //use a for loop to produce multiple upload boxes for($i = 0; $i < (count($set_one) + count($set_Two) + count($encore)); $i++){ ?> <input type ="hidden" name = "MAX_FILE_SIZE" value = "209715200" /> <fieldset><legend>Select a mp3 to upload:</legend> <?php //find and echo file/song info //first, find out which set it's in if($i < count($set_one)){ $set_num = '1'; $temp_set_array = $set_one; $count = $i; } if(($i >= count($set_one)) && ($i < (count($set_one) + count($set_Two)))){ $set_num = '2'; $temp_set_array = $set_Two; $count = $i - count($set_one); } if($i >= (count($set_one) + count($set_Two))){ $set_num = 'e'; $temp_set_array = $encore; $count = $i - count($set_one) - count($set_Two); } echo $band . " : " . $date . " : " . $temp_set_array[$count][2]; ?> <p><b>file:</b><input type="file" name ="upload[]" /></p> </fieldset> <?php //end for loop } ?> <div align="center"><input type="submit" name="submit" value="submit" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> </body> </html> Is not $_POSTing/reciving the variables $band = $_POST['band']; $year $month $day $date $setOne $setTwo and $encore when it calls itself. It's got to be a problem with the $_POSTing part, not the receiving; which should be simple, but I can't find it... Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-728203 Share on other sites More sharing options...
kenrbnsn Posted January 2, 2009 Share Posted January 2, 2009 Please post the generated HTML of the form. Ken Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-728207 Share on other sites More sharing options...
woodsonoversoul Posted January 2, 2009 Author Share Posted January 2, 2009 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>File Uploader</title> <style type="text/css" title ="text/css" media="all"> .error { font-weight: bold; color: #C00 } </style> </head> <body><pre>Array ( ) </pre><pre>Array ( [band] => Ryan Adams [year] => 2004 [month] => 2 [day] => 12 [loc] => [setOne] => Everybody Knows, Wildflowers [setTwo] => Oh My Sweet Carolina, 1974 [encore] => Warf Rat, Birdsong ) </pre>The band is: Ryan Adams<br>The show date is: 2004-02-12<br>Unique show id: ra2004-02-12<br><br><form enctype="multipart/form-data" name="upload_script_ver2.php" action="upload_script_ver2.php" method="post"><input type ="hidden" name ="band" value ="Ryan Adams" /><input type ="hidden" name ="year" value ="2004" /><input type ="hidden" name ="month" value ="2" /><input type ="hidden" name ="day" value ="12" /><input type ="hidden" name ="setOne" value ="Everybody Knows, Wildflowers" /><input type ="hidden" name ="setTwo" value ="Oh My Sweet Carolina, 1974" /><input type ="hidden" name ="encore" value ="Array" /> <input type ="hidden" name = "MAX_FILE_SIZE" value = "209715200" /> <fieldset><legend>Select a mp3 to upload:</legend> Ryan Adams : 2004-02-12 : Everybody Knows<p><b>file:</b><input type="file" name ="upload[]" /></p> </fieldset> <input type ="hidden" name = "MAX_FILE_SIZE" value = "209715200" /> <fieldset><legend>Select a mp3 to upload:</legend> Ryan Adams : 2004-02-12 : Wildflowers<p><b>file:</b><input type="file" name ="upload[]" /></p> </fieldset> <input type ="hidden" name = "MAX_FILE_SIZE" value = "209715200" /> <fieldset><legend>Select a mp3 to upload:</legend> Ryan Adams : 2004-02-12 : Oh My Sweet Carolina<p><b>file:</b><input type="file" name ="upload[]" /></p> </fieldset> <input type ="hidden" name = "MAX_FILE_SIZE" value = "209715200" /> <fieldset><legend>Select a mp3 to upload:</legend> Ryan Adams : 2004-02-12 : 1974<p><b>file:</b><input type="file" name ="upload[]" /></p> </fieldset> <input type ="hidden" name = "MAX_FILE_SIZE" value = "209715200" /> <fieldset><legend>Select a mp3 to upload:</legend> Ryan Adams : 2004-02-12 : Warf Rat<p><b>file:</b><input type="file" name ="upload[]" /></p> </fieldset> <input type ="hidden" name = "MAX_FILE_SIZE" value = "209715200" /> <fieldset><legend>Select a mp3 to upload:</legend> Ryan Adams : 2004-02-12 : Birdsong<p><b>file:</b><input type="file" name ="upload[]" /></p> </fieldset> <div align="center"><input type="submit" name="submit" value="submit" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> </body> </html> So it looks like everything is being generated properly. Also, this is the first calling of the page. It's when the page calls itself it says it's not receiving the variables... Quote Link to comment https://forums.phpfreaks.com/topic/138947-_post-variables-not-_posting/#findComment-728214 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.