hello

i'm wanting to pass information from a simple form to PHP, but i can't get it t work for me. below is what i've been working with.

heres my form ;

<form action="add.php" method="post"><input name="new_news" type="text" value="enter text" maxlength="500" /><input name="Submit" type="button" value="Submit" /></form>

and heres my PHP

   <?php
    $Submit     = $_POST["Submit"];
    $post         = $_POST["new_news"];
    $post        = ereg_replace('[^A-Za-z 0-9,./?><";:\~!\'\"\/@#[](){}]', "", $post);


if ($Submit == "Yes") {
    $filename     = "../news.txt";
    $fp         = fopen( $filename,"r+");
    $old_data     = fread($fp, 80000);
    fclose( $fp ); 



$news = "news=";
        $date        = (date ("(g:i A) l - d F Y"));
        $input         = "<p align=\"left\">$date<br>$post<br></p>";
        $new         = "$news$input$old_data";

    $fp         = fopen( $filename,"w");
    if(!$fp) die("&error    =Failed to write!");
    fwrite($fp, $new, 800000);
    fclose( $fp );
}   
?>

    Could you please tell me the error...?

      sorry, what do you mean by error?

      the information from the textfield should be passed to the php file, the file then writes it to a text file, however with the code i'm using at the moment this isn't happening. i know the php script works, so it must be an error between the form passing the information to the php file.

        EDIT: Sorry, should be something like the following:

        <?php
        
        $post   = $_POST["new_news"];
        $post   = ereg_replace('[^A-Za-z 0-9,./?><";:\~!\'\"\/@#[](){}]', "", $post);
        
        $filename = "../news.txt";
        $fp       = fopen($filename,"r+");
        $old_data = fread($fp1, 80000);
        fclose($fp);
        
        $news  = "news=";
        $date  = (date ("(g:i A) l - d F Y"));
        $input = "<p align=\"left\">$date<br>$post<br></p>";
        $new   = "$news$input$old_data";
        $fp2    = fopen($filename,"w");
        
        if(!$fp) {
        fwrite($fp2, $new, 800000);
        fclose($fp2);
        }   
        
        else {
        
        die("&error    =Failed to write!");
        
        }
        
        ?>

        If you're still having trouble, this might help you: http://www.phpfreaks.com/tutorials/36/0.php

          Your submit button should probably be type="submit" instead of type="button".

            ok, i've changed "button" to "submit" and tryed implementing the code provided by msgcrap and but still nothing.

            heres what i've got so far (keeping in mind this is being used for a weblog, and this code is for the admin 'panel');

            THE FORM, which should pass the information to add.php;

            <!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>Untitled Document</title>
            </head>
            
            <body><form action="add.php" method="post"><input name="new_news" type="text" value="enter text here" maxlength="500" /><input name="Submit" type="submit value="Submit" /></form>
            </body>
            </html>

            and, add.php, that should capture the information passed from the form and write it into the news.txt file, but isn't.

                <?php
                $Submit     = $_POST["Submit"];
                $post         = $_POST["new_news"];
                $post        = ereg_replace('[^A-Za-z 0-9,./?><";:\~!\'\"\/@#[](){}]', "", $post);
            
            
            if ($Submit == "Yes") {
                $filename     = "../news.txt";
                $fp         = fopen( $filename,"r+");
                $old_data     = fread($fp, 80000);
                fclose( $fp ); 
            
            
                $date        = (date ("(g:i A) l - d F Y"));
                $input         = "<p align=\"left\">$date<br>$post<br></p>";
                $new         = "$input$old_data";
            
                $fp         = fopen( $filename,"w");
                if(!$fp) die("&error    =Failed to write!");
                fwrite($fp, $new, 800000);
                fclose( $fp );
            }   
            ?>

            😕

              I'm pretty sure the following code is wrong

              if ($Submit == "Yes") {

              Try this:

              <?php
              
              if(isset( $Submit ))
              { 
              
              $post   = $_POST["new_news"];
              $post   = ereg_replace('[^A-Za-z 0-9,./?><";:\~!\'\"\/@#[](){}]', "", $post);
              
              $filename = "../news.txt";
              $fp       = fopen($filename,"r+");
              $old_data = fread($fp1, 80000);
              fclose($fp);
              
              $news  = "news=";
              $date  = (date ("(g:i A) l - d F Y"));
              $input = "<p align=\"left\">$date<br>$post<br></p>";
              $new   = "$news$input$old_data";
              $fp2    = fopen($filename,"w");
              
              }
              
              if(!$fp) {
              fwrite($fp2, $new, 800000);
              fclose($fp2);
              }   
              
              else {
              
              die("&error    =Failed to write!");
              
              }
              
              ?> 

              If the above doesn't work, try this:

              <?php
              
              if(isset( $Submit ))
              { 
              
              $post   = $_POST["new_news"];
              $post   = ereg_replace('[^A-Za-z 0-9,./?><";:\~!\'\"\/@#[](){}]', "", $post);
              
              $filename = "../news.txt";
              $fp       = fopen($filename,"r+");
              $old_data = fread($fp1, 80000);
              fclose($fp);
              
              $news  = "news=";
              $date  = (date ("(g:i A) l - d F Y"));
              $input = "<p align=\"left\">$date<br>$post<br></p>";
              $new   = "$news$input$old_data";
              $fp2    = fopen($filename,"w");
              
              if(!$fp) {
              fwrite($fp2, $new, 800000);
              fclose($fp2);
              }   
              
              else {
              
              die("&error    =Failed to write!");
              
              }
              }
              
              ?> 

                One thing, have you made sure that the text file has write permissions or are you using your computer?

                  yeah the permissions are fine, i initially edited news.txt from a form within flash, however due to certain reasons i've had to re-create the admin panel, outside of flash in html, so really im just trying to replicate what i had in flash. thats why i know the PHP worked, because it worked when it was receiving variable from flash, with the following actionscript

                  on (release) {
                  	if(new_news==null) {
                  	help = "<b>No news today? </b><br>:o";
                  	} else {
                  		Submit = "Yes";
                  		loadVariablesNum ("add.php", 0, "POST");
                  		gotoAndStop("admNewNews");
                  		help="<b>New news has been posted.</b><br>Please check Home confirmation."
                  		preview=new_news
                  	}
                  } 

                  I tryed the code you supplied but it returned '&error =Failed to write!', and instead of writing to the .txt file it cleared it, did you try it? if so, and it worked, then i must be doing something wrong.

                    If the content was deleted from the text file, then the mode for writing must have been wrong...

                      OK, see if this works...

                      <?php
                      
                      $Submit = $_POST['Submit'];
                      
                      if(isset( $Submit )) { 
                      
                      $post   = $_POST["new_news"];
                      $post   = ereg_replace('[^A-Za-z 0-9,./?><";:\~!\'\"\/@#[](){}]', "", $post);
                      
                      $filename = "../news.txt";
                      $fp       = fopen($filename,"r+");
                      $old_data = fread($fp1, 80000);
                      fclose($fp);
                      
                      $news  = "news=";
                      $date  = (date ("(g:i A) l - d F Y"));
                      $input = "<p align=\"left\">$date<br>$post<br></p>";
                      $new   = "$news$input$old_data";
                      $fp2   = fopen($filename,"w");
                      
                      {
                      
                      if(!$fp) {
                      fwrite($fp2, $new, 800000);
                      fclose($fp2); 
                      
                      }
                      
                      else {
                      
                      die("&error    =Failed to write!"); 
                      
                      }
                      }
                      
                      ?> 

                        hmmm, its failing to write to the news.txt file, but the &error =Failed to write! isn't showing up anymore

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

                          should be

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

                          You forgot to close the type attribute with the second quote, just a small thing.

                            i figured it out, finally!!!. It was abit of a staple and paste of different code.

                             <?php
                            
                            $Submit = $_POST['Submit'];
                            
                            if(isset( $Submit )) {
                            
                            $post   = $_POST["new_news"];
                            $post   = ereg_replace('[^A-Za-z 0-9,./?><";:\~!\'\"\/@#[](){}]', "", $post);
                            
                            $filename = "news.txt";
                            $fp       = fopen($filename,"r+");
                            $old_data = fread($fp, 80000);
                            fclose($fp);
                            
                            $date  = (date (" l - d F Y"));
                            $input = "<p align=\"left\">$date<br>$post<br></p>";
                            $new   = "$input$old_data";
                            
                            $fp         = fopen( $filename,"w");
                                    if(!$fp) die("&error    =Failed to write!");
                                    fwrite($fp, $new, 800000);
                                    fclose( $fp );
                            
                            
                            }

                            msgcrap thanks heaps! and SpecialFX cheers for that too :o

                              I'm glad for you, thanks for sharing the code :p

                              Sorry that I couldn't code it exactly for you, I'm only 13 and I've only been coding in PHP for the last couple of months.

                              I personly prefer the code like this, in one file:

                              <hml><head><title>Add News</title></head>
                              
                              <body>
                              <form action="" method="get">
                              <textarea name="newscontent"></textarea>
                              <br><br>
                              <input type="submit" name="Submit" value="Add"></form>
                              </body>
                              </html>
                              
                              <?php
                              
                              $Submit = $_GET['Submit'];
                              
                              if(isset( $Submit )) {
                              
                              $post     = $_GET['newscontent'];
                              $post     = ereg_replace('[^A-Za-z 0-9,./?><";:\~!\'\"\/@#[](){}]', "", $post);
                              
                              #news filename    
                              $filename = "news.txt"; #open news file for reading $fp = fopen($filename,"r+"); #read news file $old_data = fread($fp, 80000); fclose($fp); $date = (date (" l - d F Y")); $input = "<p align=\"left\">$date<br>$post<br></p>"; $new = "$input$old_data"; #open news file for writing $fp = fopen( $filename,"w"); if(!$fp) die("Failed to write!"); #write to news file fwrite($fp, $new, 800000); fclose( $fp ); #show success message echo("Your News was Successfully Added!"); } ?>
                                Write a Reply...