0

Html:

<form method="post" action="create.php">
Job #: <input type="text" name="jobnum">
<br>
Program: <input type="text" name="program"><br />
Ship Date: <input type="text" name="shipdate"><br />
Description: <input type="text" style="height:100px; width:85%" name="description"><br /><br />
Proto Verified By: <input type="text" name="name"><br /><br />
Additional Notes: <input type="text" style="height:100px; width:85%" name="notes"><br />
<input type="submit" name="value" value="submit" />
</form>

php:

$savedata = $_REQUEST['savedata'];
if ($savedata == 1){

$data = $_POST['jobnum']  . "\r\n";
$data .= $_POST['program']  . "\r\n";
$data .= $_POST['description']  . "\r\n";
$data .= $_POST['name'] . "\r\n";
$data .= $_POST['notes']  . "\r\n";

$file = "YOURDATAFILE.txt"; 

$fp = fopen($file, "a") or die("Couldn't open $file for writing!");
fwrite($fp, $data) or die("Couldn't write values to file!"); 

fclose($fp); 
echo "Your Form has been Submitted!";

}

I am not sure why my php will not post my form. My submit goes the the php page but it is completely blank. I am kind of new to code so I may need some detailed response...

3
  • Form has no name attribute. Commented Jan 30, 2014 at 19:29
  • Is the page blank? If so, you have errors and need to turn on error reporting to see them. Commented Jan 30, 2014 at 19:29
  • if the page is blank, write an else t if($savedata == 1) with an echo and look if it echoes your text. if so, you know that $savedata is not 1! Commented Jan 30, 2014 at 19:33

4 Answers 4

1

Try this, You have not passed or posted with name of savedata, from form submit button, i have used as below

if(isset($_POST['value'])){

instead of

$savedata = $_REQUEST['savedata'];
if ($savedata == 1){
Sign up to request clarification or add additional context in comments.

8 Comments

I did this and now its showing: Couldn't open YOURDATAFILE.txt for writing!
do I need to have an empty .txt for it to open?
fopen($file, "w+") can you add and try this! make sure your YOURDATAFILE.txt file have necessary write permissions
it gave me the same result
Can you check the file path of the file.
|
1

You need to add a hidden form field setting savedata to 1 so that your if statement will complete:

<input name="savedata" value="1" type="hidden" />

1 Comment

A possible solution. Still probably better however, to modify the PHP as the above answers suggest rather than adding more data to travel across the wire. Anyway +1
1

There's no savedata named field in the form. So i suggest that you use submit button's name to check if form is submitted. And isset() for checking value in php.

$savedata = $_REQUEST['value'];
if (isset($savedata)){
   ...

Comments

0

There is no savedata element defined in the form.

I would also suggest you to be consistent in your code, get all elements with $_POST or $_REQUEST. Also, assign value to the name attribute of the form.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.