scrappy1855 Posted January 6, 2010 Share Posted January 6, 2010 I am New to php and trying to get a form to create a text file from results. I actually got the form to work correctly with this ... <?php $customernumber = $_POST["customernumber"]; $yearwkstart = $_POST["yearwkstart"]; $yearwkend = $_POST["yearwkend"]; $email = $_POST["email"]; $file = "c:\asys_reports\baddebt.txt"; $values = "$customernumber\r\n$yearwkstart\r\n$yearwkend\r\n$email\r\n"; $fp = fopen($file, "w") or die("Couldn't open $file for writing!"); $numBytes = fwrite($fp, $values) or die("Couldn't write values to file!"); fclose($fp); if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) { $uri = 'https://'; } else { $uri = 'http://'; } $uri .= $_SERVER['HTTP_HOST']; header('Location: '.$uri.'/index_files/page2424.htm'); ?> However i'm trying to create some validation on the form and getting hung up. Here is my code... Any advise would be greatly appreciated. <?php $customernumber = $_POST["customernumber"]; $yearwkstart = $_POST["yearwkstart"]; $yearwkend = $_POST["yearwkend"]; $email = $_POST["email"]; $file = "c:\asys_reports\baddebt.txt"; $values = "$customernumber\r\n$yearwkstart\r\n$yearwkend\r\n$email\r\n"; IF (!isset($_POST["customernumber"])) { header( "Location: http://websiteurl/index_files/query.htm" ); } elseif (empty($customernumber) || empty($yearwkstart) || empty($yearwkend) || empty($email)) { header( "Location: http://websiteurl/index_files/error.htm" ); } else { $values = "$customernumber\r\n$yearwkstart\r\n$yearwkend\r\n$email\r\n"; $fp = fopen($file, "w") or die("Couldn't open $file for writing!"); $numBytes = fwrite($fp, $values) or die("Couldn't write values to file!"); fclose($fp); if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) { $uri = 'https://'; } else { $uri = 'http://'; } $uri .= $_SERVER['HTTP_HOST']; header('Location: '.$uri.'/index_files/complete.htm'); ?> Link to comment https://forums.phpfreaks.com/topic/187450-php-form-to-text-file/ Share on other sites More sharing options...
Catfish Posted January 6, 2010 Share Posted January 6, 2010 what is not working? are you getting errors or how is the data not doing what yo uwant? IF should be lower case i think. Link to comment https://forums.phpfreaks.com/topic/187450-php-form-to-text-file/#findComment-989812 Share on other sites More sharing options...
scrappy1855 Posted January 6, 2010 Author Share Posted January 6, 2010 Well what i'm trying to get it to do , is if the form is blank when submitted to reload the page , and if any of the fields have empty values to give them an error page, and then if all fields are correctly filled in, then proceed with creating the txt file and give them the completed page. However it doesn't seem to even start the validation. All 3 methods go straight to http://websiteurl/index_files/baddebt.php and say page cannot be displayed. BTW: I changed IF to if and same thing. what is not working? are you getting errors or how is the data not doing what yo uwant? IF should be lower case i think. Link to comment https://forums.phpfreaks.com/topic/187450-php-form-to-text-file/#findComment-989818 Share on other sites More sharing options...
Catfish Posted January 6, 2010 Share Posted January 6, 2010 what is baddebt.php? the name of the script? is it outputting anything or just a white page? Link to comment https://forums.phpfreaks.com/topic/187450-php-form-to-text-file/#findComment-989823 Share on other sites More sharing options...
scrappy1855 Posted January 6, 2010 Author Share Posted January 6, 2010 baddebt.php is the script file, its just going straight to page cannot be displayed. If i clear out all the validation and put back in just the original part , it works just fine. Kinda strange, I'm hoping its just some little tweak that i can't locate. It is not outputting anything at all. what is baddebt.php? the name of the script? is it outputting anything or just a white page? Link to comment https://forums.phpfreaks.com/topic/187450-php-form-to-text-file/#findComment-989828 Share on other sites More sharing options...
scrappy1855 Posted January 6, 2010 Author Share Posted January 6, 2010 Here is my code now... Its fixed mostly now. When any of the fields are missing then it goes to the Error page, and when all fields are correctly filled in then it goes to txt file correctly. I was really wanting it to just reload page if nothing was entered whatsoever. It is perfectly fine for me to go to error page when nothing is submitted as long as it doesn't create txt file. Thank you for all of your help. Next thing agenda is to add user authentication so that only 2 users can run the query. Back to Research. <?php $customernumber = $_POST["customernumber"]; $yearwkstart = $_POST["yearwkstart"]; $yearwkend = $_POST["yearwkend"]; $email = $_POST["email"]; $file = "c:\asys_reports\baddebt.txt"; $values = "$customernumber\r\n$yearwkstart\r\n$yearwkend\r\n$ email\r\n"; IF (!isset($_POST["customernumber"])) { if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) { $uri = 'https://'; } else { $uri = 'http://'; } $uri .= $_SERVER['HTTP_HOST']; header('Location: '.$uri.'/index_files/baddebtquery.htm'); } elseif (empty($customernumber) || empty($yearwkstart) || empty($yearwkend) || empty($email)) { if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) { $uri = 'https://'; } else { $uri = 'http://'; } $uri .= $_SERVER['HTTP_HOST']; header('Location: '.$uri.'/index_files/error.htm'); } else { $values = "$customernumber\r\n$yearwkstart\r\n$yearwkend\r\n$ email\r\n"; $fp = fopen($file, "w") or die("Couldn't open $file for writing!"); $numBytes = fwrite($fp, $values) or die("Couldn't write values to file!"); fclose($fp); if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) { $uri = 'https://'; } else { $uri = 'http://'; } $uri .= $_SERVER['HTTP_HOST']; header('Location: '.$uri.'/index_files/complete.htm'); } ?> Link to comment https://forums.phpfreaks.com/topic/187450-php-form-to-text-file/#findComment-989881 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.