rebbeca Posted January 31, 2008 Share Posted January 31, 2008 Hi, I'm making a site and I have a form on the site that when filled out and people click submit should allow them to download a file. The idea is that once the submit button is pressed a box will open to ask the user where they want to save the file to from the browser as usual with any file save when downloading from a site. It is, however, not working. When the form is filled out and I press submit nothing happens but the form is cleared. The php I have is as follows: <? $errors = 0; $ref = $_SERVER['HTTP_REFERER']; $email = $_POST['YPML0']; $mobile = $_POST['YPML1']; $location = $_POST['YPML2']; $wherehear = $_POST['YPML3']; $favesong = $_POST['YPML4']; // User entered email on form? if(!$email || strlen($email = trim($email)) == 0){ $errors += 1; } // Checks to see if email address is of valid type $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*" ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*" ."\.([a-z]{2,}){1}$"; if(!eregi($regex,$email)){ $errors += 1; } // User entered location? if(!$location || strlen($location = trim($location)) == 0){ $errors += 1; } // User entered where they heard about rebbeca? if(!$wherehear || strlen($wherehear = trim($wherehear)) == 0){ $errors += 1; } // User entered their fave song? if(!$favesong || strlen($favesong = trim($favesong)) == 0){ $errors += 1; } // If any errors were returned go back to the form if ($errors > 0) { header("location: ".$ref); exit(); } // Construct email $to = "info@rebbeca.info"; $from = "From: Rebbeca <album@rebbeca.info>\n"; $subject = "Album Downloaded!"; $body = "E-mail address: ".$_POST['YPML0']."\n"; if ($_POST['YPML1']) { $body .= "Mobile number: ".$_POST['YPML1']."\n"; } $body .= "Location (city / country): ".$_POST['YPML2']."\n"; $body .= "First heard about Rebbeca: ".$_POST['YPML3']."\n"; $body .= "Favourite Song: ".$_POST['YPML4']."\n"; // Send it mail($to,$subject,$body,$from); // Commence download header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="musicbynumbers.zip"'); @readfile("http://www.rebbeca.info/music-by-numbers/musicbynumbers.zip"); ?> So the question is, what have I done wrong? The html tag on the form that points to the php code is as follows: <form method="post" action="dlalbum.php"> Please note if anyone goes to the site and downloads what is uploaded it is currently a zip file of a ryan adams song and nothing to do with what the real file will be. Thanks in advance for any help. Quote Link to comment https://forums.phpfreaks.com/topic/88790-help-please/ Share on other sites More sharing options...
revraz Posted January 31, 2008 Share Posted January 31, 2008 I can only assume you are saying that the email doesn't get sent either or does it? Quote Link to comment https://forums.phpfreaks.com/topic/88790-help-please/#findComment-454756 Share on other sites More sharing options...
rebbeca Posted January 31, 2008 Author Share Posted January 31, 2008 nope, no e-mail is received either. Quote Link to comment https://forums.phpfreaks.com/topic/88790-help-please/#findComment-454759 Share on other sites More sharing options...
revraz Posted January 31, 2008 Share Posted January 31, 2008 Lets see your form code. Also, use <?php instead of just <? Maybe do a echo at the top of the page just to make sure it is being called. Quote Link to comment https://forums.phpfreaks.com/topic/88790-help-please/#findComment-454762 Share on other sites More sharing options...
rebbeca Posted January 31, 2008 Author Share Posted January 31, 2008 Form code is as follows: <form method="post" action="dlalbum.php"> <table border="0"> <tr> <td colspan="2"><strong>Fill out this form to download the album for free</strong></td> </tr> <tr> <td>E-mail address:</td> <td><input type="text" name="YMLP0" size="20"></td> </tr> <tr> <td>Mobile number (optional):</td> <td><input type="text" name="YMLP1" size="20"></td> </tr> <tr> <td>Where do you live? (city / country):</td> <td><input type="text" name="YMLP2" size="20"></td> </tr> <tr> <td>Where did you first hear about Rebbeca?:</td> <td><input type="text" name="YMLP3" size="20"></td> </tr> <tr> <td>Favourite Song?:</td> <td><input type="text" name="YMLP4" size="20"></td> </tr> <tr> <td colspan="2"><input type="submit" value="Submit"></td> </tr> </table> </form> Sorry for my ignorance but what do you mean by an echo? Quote Link to comment https://forums.phpfreaks.com/topic/88790-help-please/#findComment-454769 Share on other sites More sharing options...
rebbeca Posted January 31, 2008 Author Share Posted January 31, 2008 ok, I've looked up echo code, I never wrote that php code if anyone is wondering how I wrote that without knowing what something basic like an echo is. So what do I need to echo? The variables? Woudl this be as follows? echo $errors = 0; echo $ref; echo $email; echo $mobile; echo $location; echo $wherehear; echo $favesong; Again thanks for any help in advance Quote Link to comment https://forums.phpfreaks.com/topic/88790-help-please/#findComment-454809 Share on other sites More sharing options...
darkfreaks Posted January 31, 2008 Share Posted January 31, 2008 yes echo it out. if nothing echos there may be a problem Quote Link to comment https://forums.phpfreaks.com/topic/88790-help-please/#findComment-454832 Share on other sites More sharing options...
rebbeca Posted January 31, 2008 Author Share Posted January 31, 2008 I've added the echo code I wrote above, I've done it just below where the variables are defined. Now when I fill out the form and press submit I get the following message... 0http://rebbeca.info/newsite/pages/csssite/album.php Warning: Cannot modify header information - headers already sent by (output started at \\filer01\soho\rebbeca.info\www.rebbeca.info\web\content\newsite\pages\csssite\dlalbum.php:10) in \\filer01\soho\rebbeca.info\www.rebbeca.info\web\content\newsite\pages\csssite\dlalbum.php on line 43 Quote Link to comment https://forums.phpfreaks.com/topic/88790-help-please/#findComment-454845 Share on other sites More sharing options...
darkfreaks Posted January 31, 2008 Share Posted January 31, 2008 put ob_start at the top of your code Quote Link to comment https://forums.phpfreaks.com/topic/88790-help-please/#findComment-454850 Share on other sites More sharing options...
rebbeca Posted January 31, 2008 Author Share Posted January 31, 2008 thanks, now I get the following error: Parse error: parse error, unexpected T_VARIABLE in \\filer01\soho\rebbeca.info\www.rebbeca.info\web\content\newsite\pages\csssite\dlalbum.php on line 3 I looked up ob_Start and it looks like there should be something in brackets after the ob_Start, is this the case? Just as an update, here is what the php file is now looking like: <? ob_start $errors = 0; $ref = $_SERVER['HTTP_REFERER']; $email = $_POST['YPML0']; $mobile = $_POST['YPML1']; $location = $_POST['YPML2']; $wherehear = $_POST['YPML3']; $favesong = $_POST['YPML4']; echo $errors = 0; echo $ref; echo $email; echo $mobile; echo $location; echo $wherehear; echo $favesong; // User entered email on form? if(!$email || strlen($email = trim($email)) == 0){ $errors += 1; } // Checks to see if email address is of valid type $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*" ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*" ."\.([a-z]{2,}){1}$"; if(!eregi($regex,$email)){ $errors += 1; } // User entered location? if(!$location || strlen($location = trim($location)) == 0){ $errors += 1; } // User entered where they heard about rebbeca? if(!$wherehear || strlen($wherehear = trim($wherehear)) == 0){ $errors += 1; } // User entered their fave song? if(!$favesong || strlen($favesong = trim($favesong)) == 0){ $errors += 1; } // If any errors were returned go back to the form if ($errors > 0) { header("location: ".$ref); exit(); } // Construct email $to = "info@rebbeca.info"; $from = "From: Rebbeca <album@rebbeca.info>\n"; $subject = "Album Downloaded!"; $body = "E-mail address: ".$_POST['YPML0']."\n"; if ($_POST['YPML1']) { $body .= "Mobile number: ".$_POST['YPML1']."\n"; } $body .= "Location (city / country): ".$_POST['YPML2']."\n"; $body .= "First heard about Rebbeca: ".$_POST['YPML3']."\n"; $body .= "Favourite Song: ".$_POST['YPML4']."\n"; // Send it mail($to,$subject,$body,$from); // Commence download header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="musicbynumbers.zip"'); @readfile("http://www.rebbeca.info/music-by-numbers/musicbynumbers.zip"); ?> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/88790-help-please/#findComment-454854 Share on other sites More sharing options...
darkfreaks Posted January 31, 2008 Share Posted January 31, 2008 <?php ob_start; $errors = 0; $ref = $_SERVER['HTTP_REFERER']; $email = $_POST['YPML0']; $mobile = $_POST['YPML1']; $location = $_POST['YPML2']; $wherehear = $_POST['YPML3']; $favesong = $_POST['YPML4']; echo $errors = 0; echo $ref; echo $email; echo $mobile; echo $location; echo $wherehear; echo $favesong; // User entered email on form? if(!$email || strlen($email = trim($email)) == 0){ $errors += 1; } // Checks to see if email address is of valid type $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*" ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*" ."\.([a-z]{2,}){1}$"; if(!eregi($regex,$email)){ $errors += 1; } // User entered location? if(!$location || strlen($location = trim($location)) == 0){ $errors += 1; } // User entered where they heard about rebbeca? if(!$wherehear || strlen($wherehear = trim($wherehear)) == 0){ $errors += 1; } // User entered their fave song? if(!$favesong || strlen($favesong = trim($favesong)) == 0){ $errors += 1; } // If any errors were returned go back to the form if ($errors > 0) { header("location: ".$ref); exit(); } // Construct email $to = "info@rebbeca.info"; $from = "From: Rebbeca <album@rebbeca.info>\n"; $subject = "Album Downloaded!"; $body = "E-mail address: ".$_POST['YPML0']."\n"; if ($_POST['YPML1']) { $body .= "Mobile number: ".$_POST['YPML1']."\n"; } $body .= "Location (city / country): ".$_POST['YPML2']."\n"; $body .= "First heard about Rebbeca: ".$_POST['YPML3']."\n"; $body .= "Favourite Song: ".$_POST['YPML4']."\n"; // Send it mail($to,$subject,$body,$from); // Commence download header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="musicbynumbers.zip"'); @readfile("http://www.rebbeca.info/music-by-numbers/musicbynumbers.zip"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/88790-help-please/#findComment-454855 Share on other sites More sharing options...
rebbeca Posted January 31, 2008 Author Share Posted January 31, 2008 I'm really sorry and I'm sure I'm testing your patience to an extreme, I copied your code word for word but I now get the following error..... 0http://rebbeca.info/newsite/pages/csssite/album.php Warning: Cannot modify header information - headers already sent by (output started at \\filer01\soho\rebbeca.info\www.rebbeca.info\web\content\newsite\pages\csssite\dlalbum.php:11) in \\filer01\soho\rebbeca.info\www.rebbeca.info\web\content\newsite\pages\csssite\dlalbum.php on line 44 Quote Link to comment https://forums.phpfreaks.com/topic/88790-help-please/#findComment-454859 Share on other sites More sharing options...
darkfreaks Posted January 31, 2008 Share Posted January 31, 2008 <?php $errors = 0; $ref = $_SERVER['HTTP_REFERER']; $email = $_POST['YPML0']; $mobile = $_POST['YPML1']; $location = $_POST['YPML2']; $wherehear = $_POST['YPML3']; $favesong = $_POST['YPML4']; echo $errors = 0; echo $ref; echo $email; echo $mobile; echo $location; echo $wherehear; echo $favesong; // User entered email on form? if(!$email || strlen($email = trim($email)) == 0){ $errors += 1; } // Checks to see if email address is of valid type $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*" ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*" ."\.([a-z]{2,}){1}$"; if(!eregi($regex,$email)){ $errors += 1; } // User entered location? if(!$location || strlen($location = trim($location)) == 0){ $errors += 1; } // User entered where they heard about rebbeca? if(!$wherehear || strlen($wherehear = trim($wherehear)) == 0){ $errors += 1; } // User entered their fave song? if(!$favesong || strlen($favesong = trim($favesong)) == 0){ $errors += 1; } // If any errors were returned go back to the form if ($errors > 0) { ob_start; header("location: ".$ref); exit(); } // Construct email $to = "info@rebbeca.info"; $from = "From: Rebbeca <album@rebbeca.info>\n"; $subject = "Album Downloaded!"; $body = "E-mail address: ".$_POST['YPML0']."\n"; if ($_POST['YPML1']) { $body .= "Mobile number: ".$_POST['YPML1']."\n"; } $body .= "Location (city / country): ".$_POST['YPML2']."\n"; $body .= "First heard about Rebbeca: ".$_POST['YPML3']."\n"; $body .= "Favourite Song: ".$_POST['YPML4']."\n"; // Send it mail($to,$subject,$body,$from); // Commence download header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="musicbynumbers.zip"'); @readfile("http://www.rebbeca.info/music-by-numbers/musicbynumbers.zip"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/88790-help-please/#findComment-454861 Share on other sites More sharing options...
rebbeca Posted February 1, 2008 Author Share Posted February 1, 2008 now it's saying : 0http://rebbeca.info/newsite/pages/csssite/album.php Warning: Cannot modify header information - headers already sent by (output started at \\filer01\soho\rebbeca.info\www.rebbeca.info\web\content\newsite\pages\csssite\dlalbum.php:11) in \\filer01\soho\rebbeca.info\www.rebbeca.info\web\content\newsite\pages\csssite\dlalbum.php on line 45 It seems that my line error just keeps increasing by 1! If I give someone the server codes and let them test it themselves how much would it cost to get someone to do it all? Quote Link to comment https://forums.phpfreaks.com/topic/88790-help-please/#findComment-454870 Share on other sites More sharing options...
darkfreaks Posted February 1, 2008 Share Posted February 1, 2008 it is because you have $ref= [http_request_method]; then in your header have $ref which does the same thingas header Quote Link to comment https://forums.phpfreaks.com/topic/88790-help-please/#findComment-454876 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.