CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2007
    Posts
    7

    Arrow Please help me , Post Data & Store Data

    Hi guys

    want to make a form with 2 actions, means by 1 click 2 actions performs and I do not want to use PHP_SELF, because the first action address is the main target and the second one is to store data

    its my code but it doesn't store data in "test.txt" just posts to "http://mysite.com/11.php"
    PHP Code:
    <?php
    $st 
    "
    <form action='http://mysite.com/11.php' method='post'>
    Name: <input type='text' name='name' />
    Age: <input type='text' name='age' />
    <input type='submit' />
    </form>
    "
    ;
    echo 
    $st;

    $name stripslashes($name);
    $age stripslashes($age);
    $logs fopen('test.txt''a'1);
    $mytext="
    $name , $age ";

    fwrite($logs$mytext);
    fclose($logs);

    ?>

    Thanks

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Please help me , Post Data & Store Data

    Well, I don't understand the 1 in your fopen(), nor do I understand why your variable to be written is two lines. Just use \n to do line returns.

    Use the following to see where your code is failing.
    PHP Code:
    $name stripslashes($name);
    $age stripslashes($age);
    if(
    $logs fopen('test.txt''a')){
      
    $mytext="\n$name , $age";
      if(!
    fwrite($logs$mytext)){echo 'Could not write to file.';}
      
    fclose($logs);
    }
    else{echo 
    'File could not be opened!';} 
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Feb 2007
    Posts
    7

    Re: Please help me , Post Data & Store Data

    problem is not on writing of file
    it will writes if you change the post action to 11.php , but it will just post data localy and saves data to file and doesn't send the data to the other site , how ever i want to the script does both

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Please help me , Post Data & Store Data

    Oh, well then why don't you just put the fwrite code in the 11.php? That is your server-side script file.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Feb 2007
    Posts
    7

    Re: Please help me , Post Data & Store Data

    because i don't have access to 2nd host

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: Please help me , Post Data & Store Data

    Then you have to use JavaScript to submit the form once with a different window being the target, and then again with the regular window.

    Code:
    function submitform(){
      document.formname.action = "http://mysite.com/11.php";
      document.formname.target = "_blank";
      document.formname.submit;
      document.formname.action = "";
      document.formname.target = "_self";
      document.formname.submit;  
    }
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Feb 2007
    Posts
    7

    Re: Please help me , Post Data & Store Data

    thanks , it worked

  8. #8
    Join Date
    May 2002
    Posts
    10,943

    Re: Please help me , Post Data & Store Data

    Glad to hear it. You're welcome.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured