Click to See Complete Forum and Search --> : Please help me , Post Data & Store Data


thepolaris
March 23rd, 2007, 05:09 AM
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
$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

PeejAvery
March 23rd, 2007, 07:36 AM
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.
$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!';}

thepolaris
March 23rd, 2007, 08:47 AM
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

PeejAvery
March 23rd, 2007, 08:53 AM
Oh, well then why don't you just put the fwrite code in the 11.php? That is your server-side script file.

thepolaris
March 23rd, 2007, 09:40 AM
because i don't have access to 2nd host

PeejAvery
March 23rd, 2007, 10:04 AM
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.

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;
}

thepolaris
March 23rd, 2007, 06:11 PM
thanks , it worked ;)

PeejAvery
March 23rd, 2007, 06:12 PM
Glad to hear it. You're welcome.