lindsaycb Posted March 25, 2011 Share Posted March 25, 2011 I have a URL https://www.kishwaukeecollege.edu/staff/mykcw/arr/recruit.php?month=04 and the PHP file associated with the button creates a CSV. I have the code $SELmonth = $_GET['month']; and $year = date("Y"); in that PHP file but creating a filename using that is only showing the year. The button has a hidden value of the month and is using action=post while I'm using get in the PHP but if I change it to match (either both using Post or Get), then the filename downloads with 2007 instead of the current year of 2011. So how can I grab the ?month=04 from the URL? Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 25, 2011 Share Posted March 25, 2011 The button has a hidden value of the month and is using action=post while I'm using get in the PHP but if I change it to match (either both using Post or Get), then the filename downloads with 2007 instead of the current year of 2011. I'm not following you. If you have the month in the URL, then why do you have the month in a hidden field. Use one or the other. Regarding the month in the URL is that the URL you use to access the page with the form (i,e. button)? If so, when you POST the form that value is not getting included as part of the url. I suspect you are using the month on the URL to populate the hidden field in the form. I would just use the $_POST['month'] value. Quote Link to comment Share on other sites More sharing options...
lindsaycb Posted March 25, 2011 Author Share Posted March 25, 2011 The hidden field on the button was just in case the PHP code wasn't grabbing it from the URL. Yes, that's the URL I use to access the form. The original link will be the current month, which is 03 for this month. There's a drop down to change months. I changed it to $_POST in the CSV PHP code and the download filename is still only showing the year and it's not even the correct year now, it's 2007. So my $year = date("Y"); is not working now. Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 25, 2011 Share Posted March 25, 2011 The hidden field on the button was just in case the PHP code wasn't grabbing it from the URL. Yes, that's the URL I use to access the form. The original link will be the current month, which is 03 for this month. There's a drop down to change months. I changed it to $_POST in the CSV PHP code and the download filename is still only showing the year and it's not even the correct year now, it's 2007. So my $year = date("Y"); is not working now. OK, if you are using that link above to ACCESS the form, then that value will not be available to the script that processes the form since the form will post to the URL in the "action" parameter of the form tag. If you are already saving the value into a hidden field I still think you should go ahead and access the field via the POST array. You say that the value is not available in the POST data AND the year is resolving to 2007. For the first part you should do a print_r($_POST) on the processing page to validate exactly what is being passed int he post data. As for the year resolving to 2007 - that makes no sense. The code you provide above will determine the current year, regardless of what values are, or are not passed. There must be something else going on that you are not aware of. You may be POSTing to the wrong page, there are IF/ELSE conditions that are causing the code to evaluate differently than you expect, something. Quote Link to comment Share on other sites More sharing options...
lindsaycb Posted March 28, 2011 Author Share Posted March 28, 2011 Figured it out. It was this code: header("Content-disposition: filename=".$SELmonth.'-'.$year.".csv"); Needed to have the dots around the variable with the dash in the single quotes. 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.