Reputation: 4751
In the same server, I have a page called mkwars
and another called generatedtab
. Inside mkwars I have a lot of input fields that contains numeric numbers.I need to transfer the datas from those inputs, to another new inputs located in the page generatedtab
.
This is the HTML code:
<table border="0" id="table1" align="center" cellspacing="0" cellpadding="3" width="100%">
<tr>
<td width="50%" valign="top"><b>Home Clan:</b> <input type="text" id="clan1" name="clan1" onchange="nomewar();"/></td>
<td><b>Opponent Clan: </b> <input type="text" id="clan2" name="clan2" onchange="nomewar();"/></td>
</tr>
</table>
//other code
<form method="post" action="savewar.php">
<input type="submit" Value="Generate Table" style="height:70px;width:800px" />
</form>
And here you can see the PHP file:
<?
$percorso = file("war/filedb.txt");
while(list(,$value) = each($percorso)){
list($clan1, $clan2) = split("[:]", $value);
$params["clan1"] = trim($clan1);
$params["clan2"] = trim($clan2);
#print results
echo $params["clan1"]." - ".$params["clan2"]."<br />";
}
?>
war
is a folder inside my server. When I click the button Generate Table I can't see the file (war/filedb.txt). Could you help me? I thought that the PHP way was the better, but if you think that I should do something else, tell me.
Upvotes: 2
Views: 171
Reputation: 326
I'm not exactly clear on what you're trying to do here. I think you want to fill out the html form and have the php script save the new input into a file on the server, and then print out the contents of the file. If that's correct, here are a few things you need to fix.
1) On your html page, the <form>
tag must enclose all of the input fields you want to post back to the server. so:
<form method="post" action="savewar.php">
<table border="0" id="table1" align="center" cellspacing="0" cellpadding="3" width="100%">
<tr>
<td width="50%" valign="top"><b>Home Clan:</b> <input type="text" id="clan1" name="clan1" onchange="nomewar();"/></td>
<td><b>Opponent Clan: </b> <input type="text" id="clan2" name="clan2" onchange="nomewar();"/></td>
</tr>
</table>
<input type="submit" Value="Generate Table" style="height:70px;width:800px" />
</form>
2) In your php script, you need to use the superglobal $_POST or $_REQUEST variable to catch the data from the posted form. For example:
$clan1 = $_POST['clan1'];
$clan2 = $_POST['clan2'];
3) In your php script, you need to open the file for writing and append the new data to the end of the file:
$fileappendpointer = fopen("war/filedb.txt",'a');
$newline = $clan1 . " - " . $clan2 . "<br>";
fwrite($fileappendpointer, $newline);
4) Then you can easily read out the contents of the file:
fclose($fileappendpointer);
$filereadpointer = fopen("war/filedb.txt",'r');
$contents = fread($filereadpointer,filesize("war/filedb.txt"));
fclose($filereadpointer);
print $contents;
Upvotes: 1