Hello,
How do I post a new value with a form to PHP? I have a table of data and when I click one of the <td>-cells it switches to a text input area where I can type the new value and then update that row. Everything works just fine except the new value is not forwarded with that form, only the old one. I'm using mysql and php.
Here are parts of my code:
var edit = false;
function editme (e,name,variable) {
if(!edit) {
e.innerHTML = "<input type='text' id='" + name + "' cols='2' name='" + name + "' value='" + variable + "'>";
edit = true;
}
}
<?php
for ($i = 0; $i < mysql_num_rows($taulukko); $i++) {
$id = mysql_result($taulukko, $i, 0);
$pvm = mysql_result($taulukko, $i, 1);
$tankattu = mysql_result($taulukko, $i, 2);
$ajettu = mysql_result($taulukko, $i, 3);
$hinta = mysql_result($taulukko, $i, 4);
$kustannus = mysql_result($taulukko, $i, 5);
echo "<form id=\"Update\" action=\"bensa.php\" method=\"POST\">
<input type=\"hidden\" name=\"Update\" id=\"Update\" value=\"Update\">
<input type=\"hidden\" name=\"id\" id=\"id\" value=\"$id\">
<input type=\"hidden\" name=\"pvm\" id=\"pvm\" value=\"$pvm\">
<input type=\"hidden\" name=\"tankattu\" id=\"tankattu\" value=\"$tankattu\">
<input type=\"hidden\" name=\"ajettu\" id=\"ajettu\" value=\"$ajettu\">
<input type=\"hidden\" name=\"hinta\" id=\"hinta\" value=\"$hinta\">
<input type=\"hidden\" name=\"kustannus\" id=\"kustannus\" value=\"$kustannus\">
<tr>
<td onclick=\"editme(this,pvm,$pvm)\">$pvm</td>
<td onclick=\"editme(this,tankattu,$tankattu)\">$tankattu l</td>
<td onclick=\"editme(this,ajettu,$ajettu)\">$ajettu km</td>
<td onclick=\"editme(this,hinta,$hinta)\">$hinta €</td>
<td onclick=\"editme(this,kustannus,$kustannus)\">$kustannus</td>
<td><input type=\"submit\" value=\"Update\"></p></td>
</tr>
</form>"; }
So this works pretty find, except MySQL only receives the old value, because I set it in the hidden value. So how do I change that to accept the new value from editme() ?
Or is this possible/more easily done by some other way?
- AnttiK