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: <?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
You have a couple of issues. Oddly enough, the writers of functions like fopen and fwrite provide a means of testing them for success. You seem to believe that is a wasted, worthless effort, since you don't use it. You may succeed occassionally, but not as a real programmer. Worse, you seem to think that the client and server side actions are interactive on an intimate scale. They are not. At the time your shown code runs, it constructs a document that will ask for the given information. It then transmits that document to the client and closes the connection. At that time there is no user information available for test.txt other than what you have stuffed in the variables, yourself. In this case, that is zero, zip, zilch, nada, nothing. Your program terminates, having disappointed you in your expectations. At some later time, maybe, and maybe never, a client may fill in the form and press the submit button. At this time a new request is made of your server: specifically, that it will execute a file named 11.php, located on a path whose URL is http://mysite.com/. There is no indication from you that this file is the same file as the one you show. This new (same?) file will be provided with the information that formed the NEW request, including POST information. It will be the responsibility of this different file (or the one you show, if that is indeed its name, and IF YOU ADD TO IT, to grab this information and store it away in test.txt. Think of this client/server as more of a walkie talkie communication than as a telephone conversation. There is no intimate interaction. Requests are made. Responses are given. The server has no inkling of your user moving the mouse or banging on the keyboard. Your server doesn't know if the client is there or not. If you want any continuity, you have to build it in. Even so, it isn't guaranteed. The client has to cooperate, one way or another, in sustaining it.