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"
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
Everything looks good here, does test.txt have world permission (Writable permission, 777)?
You might want to put a condition to handle if the file is not open, then you will be able to determine if the file is open.
Code:if (($fp = fopen($filename, "r+") === FALSE) {
// handle error
exit;
}
problem is not premission
it can write if you change the action to 11.php, but if you do it , it just writes in the file , and doesn't post data to mysite.com/11.php
but try this..
i'm pretty sure that this does the job..Code:<?php
function form(){
<form action='myfile.php?act=write' method='post'>
Name: <input type='text' name='name' />
Age: <input type='text' name='age' />
<input type='submit' />
</form>
}
function write(){
$name = $_REQUEST['name'];
$age = $_REQUEST['age'];
$name = stripslashes($name);
$age = stripslashes($age);
$logs = fopen('test.txt', 'a', 1);
$mytext="
$name , $age ";
fwrite($logs, $mytext);
fclose($logs);
}
switch($act){
default;
form();
break;
case "write";
write();
break;
}
?>
just change this:
<form action='myfile.php?act=write' method='post'>
thanks but its php_self and i want to post the data to another site 'http://mysite.com/11.php'
well hmm.. ookay:
form.php
Now you must insert this part into your 11.php file:Code:<?php
echo "<form action='http://mysite.com/11.php' method='post'>
Name: <input type='text' name='name' /><br>
Age: <input type='text' name='age' /><br>
<input type='submit' />
</form>";
?>
and it worksCode:<?php
$name = $_POST['name'];
$age = $_POST['age'];
$name = stripslashes($name);
$age = stripslashes($age);
$logs = fopen('test.txt', 'w');
$mytext="
$name , $age ";
$write = fwrite($logs, $mytext);
if(!$write){
die("Can not write info into file!");
}
fclose($logs);
?>![]()
thanks , worked![]()
you're welcome![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks