Jump to content

[SOLVED] why isn't my form working?


ohdang888

Recommended Posts

this is my form. its for people to send me suggestions about my ads...

iwhile testing it, its creating the file and writing:

 

,Rate-Useful:,rate-position:,suggestions:../suggestions.txt......

 

but its not writing the information down...

its a pretty simple code too, thats why its maing me mad.

heres the code ...

 

 

 

<form method="post" >

E-Mail:<input type="text" size="15" maxlength="30" name="e_mail"/>

<br/>

Rate how useful our ads were!

<br>

<font size=2> 1= Terrible, 5=Great <br>

<font size=3>

<select name="rate_useful">

<option value="1">1</option>

<option value="2">2</option>

<option value="3">3</option>

<option value="4">4</option>

<option value="5">5</option>

</select>

<br>

Rate the location of our ads on the webpage were!

<br>

<font size=2> 1= Terrible, 5=Great<br>

<font size=3>

<select name="position">

<option value="1">1</option>

<option value="2">2</option>

<option value="3">3</option>

<option value="4">4</option>

<option value="5">5</option>

</select>

<br>

Got Any Suggestions?

<br>

<textarea rows="2" cols="20" name="suggestions"/>

<input type="submit" name="click" value="click"/>

</form>

<?php

  $email = $_POST["e_mail"];

  $use = $_POST["rate_useful"];

  $position = $_POST["position"];

  $comments = $_POST["suggestions"];

  $suggestions = "../suggestions.txt";

  $FH = fopen($suggestions, 'a+') or die("can't open file");

  fwrite($FH,$email . ',Rate-Useful:' . $use . ',rate-position:' . $position . ',suggestions:' . $suggestions . '......');

  fclose($FH);

?>

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/83169-solved-why-isnt-my-form-working/
Share on other sites

You just had an unclosed <textarea> (not sure if that was your problem)

 

It writes to the file ok (make sure that the file you are writing to has the correct permissions, if you aren't sure, just delete the submissions.txt file, php will make the file automatically with the correct permissions if the file does not already exist)

 

You might also want to think about giving some feedback to the user to let them know when they've submitted the data successfully, otherwise they might keep clicking and fill up your data file :P

 

<form method="post" >
E-Mail:<input type="text" size="15" maxlength="30" name="e_mail"/>
<br />


Rate how useful our ads were!


<font size=2> 1= Terrible, 5=Great

<font size=3>
<select name="rate_useful">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>


<br />
Rate the location of our ads on the webpage were!


<font size=2> 1= Terrible, 5=Great

<font size=3>
<select name="position">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>


<br />
Got Any Suggestions?


<textarea rows="2" cols="20" name="suggestions"/></textarea><br>
<input type="submit" name="click" value="click"/>
</form>

<?php
  $email = $_POST["e_mail"];
  $use = $_POST["rate_useful"];
  $position = $_POST["position"];
  $comments = $_POST["suggestions"];
  $suggestions = "../suggestions.txt";
  $FH = fopen($suggestions, 'a+') or die("can't open file");
  fwrite($FH,$email . ',Rate-Useful:' . $use . ',rate-position:' . $position . ',suggestions:' . $suggestions . '......');
  fclose($FH);
?>

 

seems to work for me

The PHP part of you script should only be executed after the form is submitted. The way you have it, it get executed before the form is displayed.

 

Try this:

<?php
if (isset($_POST['click'])) {
  $email = $_POST["e_mail"];
  $use = $_POST["rate_useful"];
  $position = $_POST["position"];
  $comments = $_POST["suggestions"];
  $suggestions = "../suggestions.txt";
  $FH = fopen($suggestions, 'a+') or die("can't open file");
  fwrite($FH,$email . ',Rate-Useful:' . $use . ',rate-position:' . $position . ',suggestions:' . $suggestions . " .... \r\n");
  fclose($FH);
}
?>
<form method="post" >
E-Mail:<input type="text" size="15" maxlength="30" name="e_mail"/>


Rate how useful our ads were!


<font size=2> 1= Terrible, 5=Great

<font size=3>
<select name="rate_useful">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>


Rate the location of our ads on the webpage were!


<font size=2> 1= Terrible, 5=Great

<font size=3>
<select name="position">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>


Got Any Suggestions?


<textarea rows="2" cols="20" name="suggestions"></textarea>
<input type="submit" name="click" value="click"/>
</form>

 

Ken

 

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.