Jump to content

Create report


BrianM

Recommended Posts

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

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

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

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. :o

 

Thanks for your help!

Link to comment
https://forums.phpfreaks.com/topic/105817-create-report/#findComment-542416
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.