BrianM Posted May 15, 2008 Share Posted May 15, 2008 Alright, to start things off, here is what I have so far -- <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>MPS - Create Report</title> </head> <?php ?> <body> Report Title: <br /> <input type="text" name="report_title" /> <br /> Report Content: <br /> <textarea rows="10" cols="65" name="report_text" onFocus="this.value=''; this.onfocus=null;">Type a report in here and click 'Create' when you are finished...</textarea> <br /> <input type="submit" name="report_create" value="Create" /> </body> </html> Not much, I know. Well is what I'm aiming for here is, I want to type information (or rather, a report), and hit the Create button, after that it copies what you typed to a new file (*.php -- ex. report_title.php), and that's about it. Anyone have an example of how this is done? Quote Link to comment Share on other sites More sharing options...
soycharliente Posted May 15, 2008 Share Posted May 15, 2008 Check this out. http://www.tizag.com/phpT/files.php It helped me create a file on the server from data generated on a page. Click Continue at the bottom to move to the next page. There's also a menu on the left too. If you scroll down you can see that they distinguish what page you're on. Quote Link to comment Share on other sites More sharing options...
BrianM Posted May 15, 2008 Author Share Posted May 15, 2008 Well I got something working from the example you gave me. I'll post my code and then explain my problem -- <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>MPS - Report</title> </head> <?php $report_title = $_POST['report_title']; // line 8 $report_text = $_POST['report_text']; // line 9 if (isset($_POST['report_create'])) { $file = fopen("$report_title.php","w"); fwrite($file,"$report_text"); fclose($file); } ?> <body> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> Report Title: <br /> <input type="text" name="report_title" /> <br /> Report Content: <br /> <textarea rows="10" cols="65" name="report_text" onFocus="this.value=''; this.onfocus=null;">Type a report in here and click 'Create' when you are finished...</textarea> <br /> <input type="submit" name="report_create" value="Create" /> </form> </body> </html> Well now it's working fine, except at the top of the page, before I submit my entry it reads the following before my form -- Notice: Undefined index: report_title in C:\Program Files\Apache Group\Apache2\htdocs\mps\reports\index.php on line 8 Notice: Undefined index: report_text in C:\Program Files\Apache Group\Apache2\htdocs\mps\reports\index.php on line 9 I've noted which lines 8 and 9 are in the code for quicker reference to anyone wanting to throw some advice my way. Quote Link to comment Share on other sites More sharing options...
soycharliente Posted May 15, 2008 Share Posted May 15, 2008 Put this at the top of the page and it will show you the $_POST array. You can see exactly what's getting sent. Every index being sent and each value for each index. <?php print_r($_POST); ?> Quote Link to comment Share on other sites More sharing options...
BrianM Posted May 15, 2008 Author Share Posted May 15, 2008 All it's returning when I do that is, "Array ( )" Is it suppose to be anything else? Quote Link to comment Share on other sites More sharing options...
soycharliente Posted May 15, 2008 Share Posted May 15, 2008 You have to submit the form to see something. Does it do that even after you submit the form? Quote Link to comment Share on other sites More sharing options...
BrianM Posted May 15, 2008 Author Share Posted May 15, 2008 It would only show the undefined variable errors prior to hitting the submit button and the code works just fine. And I did happen to fix the problem, I found it in an older post. You can't store variables that are in a function outside of that function that parses the info naming the variable with $_POST data, or something along those lines, I understood it though and fixed it. Thanks for your help! Quote Link to comment Share on other sites More sharing options...
soycharliente Posted May 15, 2008 Share Posted May 15, 2008 I don't really see where you've defined a function, but if it works, yay! Mark solved. 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.