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? Link to comment https://forums.phpfreaks.com/topic/105817-create-report/ 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. Link to comment https://forums.phpfreaks.com/topic/105817-create-report/#findComment-542327 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. Link to comment https://forums.phpfreaks.com/topic/105817-create-report/#findComment-542396 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); ?> Link to comment https://forums.phpfreaks.com/topic/105817-create-report/#findComment-542404 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? Link to comment https://forums.phpfreaks.com/topic/105817-create-report/#findComment-542405 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? Link to comment https://forums.phpfreaks.com/topic/105817-create-report/#findComment-542410 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! Link to comment https://forums.phpfreaks.com/topic/105817-create-report/#findComment-542416 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. Link to comment https://forums.phpfreaks.com/topic/105817-create-report/#findComment-542423 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.