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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.