0

Im sorry to bother all of you but im a complete retard when it comes to scripting etc.

More to the point: I downloaded a completed script but im getting error
Notice: Undefined index: input_name in \index.php on line 17
and
Notice: Undefined index: input_text in \index.php on line 18

I know i just have to define them but i have no idea how to do that. If anyone is willing to help it would be lovley. Here is the code

<?php

         $file = "shouts.txt";
?>
<p>
  <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
    <input type="text" value="Gamernick" name="input_name" /><br />
    <input type="text" value="Suggestion/Feedback" name="input_text" /><br />
    <input type="submit" value="Send Feedback!" />
  </form>
</p>
<hr />
<p>
</p><p>
<?php
  //insert new shout
  $input_name = $_POST["input_name"];
  $input_text = $_POST["input_text"];

  //check if form has been submitted
  if(isset($input_name) && isset($input_text) && $input_name!="Your name" && $input_text!="Your text" && strlen($input_name)>0 && strlen($input_text)>0){
    $handle = fopen($file,"a"); //open shouts file to write (append)
    fputs($handle,"$input_name|||||$input_text\n"); //insert name and shout
    fclose($handle); //close file handle
  }
2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by poolean
1

Basically it's just a notice. It still works but it is expecting the 2 values to pass from the previous page.

I believe it works when you hit the "Send feedback!" button and the error appears only when you first load the page.

You can add some kind of validation or a check if anything is submitted before you run line 17 to line 25.

You can try the following:

<?php
         $file = "shouts.txt";
?>
<p>
  <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
    <input type="text" value="Gamernick" name="input_name" /><br />
    <input type="text" value="Suggestion/Feedback" name="input_text" /><br />
    <input type="submit" value="Send Feedback!" />
  </form>
</p>
<hr />
<p>
</p><p>
<?php
  //insert new shout
  if ($_POST) {
      $input_name = $_POST["input_name"];
      $input_text = $_POST["input_text"];
      //check if form has been submitted
      if(isset($input_name) && isset($input_text) && $input_name!="Your name" && $input_text!="Your text" && strlen($input_name)>0 && strlen($input_text)>0){
        $handle = fopen($file,"a"); //open shouts file to write (append)
        fputs($handle,"$input_name|||||$input_text\n"); //insert name and shout
        fclose($handle); //close file handle
      }
  }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.