Hi Phreaks!
I need to make a Query page with a HTML Table where all records will be displayed. Each one has a Radio button when checked it should pass the value to an other page where a query will be executed based on the passed value. The result should then be displayed in editable Textboxes. My Problem is that the query on the second page never gets the value from the selection. I think my example does not work because of the Globals which are set off!
I also tried to use "$_POST['value']" but without the expected result. Maybe some one can help me and give me an example how to do it right. I ‘m a newbie to PHP so please don’t wonder about my question and sorry for my English which is not my native lang.
Here is the Code of my example
Page1:
<html>
<body>
Wählen Sie aus, welcher Datensatz geändert werden soll:<p>
<form action = "uf16b.php" method = "post">
<?php
$db = mysql_connect('xxx','xxx','xxx');
$res = mysql_db_query("firma",
"select * from personen");
$num = mysql_num_rows($res);
// Tabellenbeginn
echo "<table border>";
// Überschrift
echo "<tr> <td>Auswahl</td> <td>Name</td>";
echo "<td>Vorname</td> <td>Personalnummer</td>";
echo "<td>Gehalt</td> <td>Geburtstag</td> </tr>";
for ($i=0; $i<$num; $i++)
{
$nn = mysql_result($res, $i, "name");
$vn = mysql_result($res, $i, "vorname");
$pn = mysql_result($res, $i, "personalnummer");
$ge = mysql_result($res, $i, "gehalt");
$gt = mysql_result($res, $i, "geburtstag");
// Tabellenzeile mit -zellen
echo "<tr> <td><input type='radio' name='auswahl'";
echo " value='$pn'></td> <td>$nn</td> <td>$vn</td>";
echo "<td>$pn</td> <td>$ge</td> <td>$gt</td> </tr>";
}
// Tabellenende
echo "</table>";
mysql_close($db);
?>
<p>
<input type="submit" value="Datensatz anzeigen">
</form>
</body>
</html>
Page2:
<html>
<body>
<?php
if ($auswahl)
{
$db = mysql_connect('xxx','xxx','xxx');
$sqlab = "select * from personen where";
$sqlab .= " personalnummer = $auswahl";
$res = mysql_db_query("firma", $sqlab);
$altnn = mysql_result($res, 0, "name");
$altvn = mysql_result($res, 0, "vorname");
$altge = mysql_result($res, 0, "gehalt");
$altgt = mysql_result($res, 0, "geburtstag");
echo "Führen Sie die Änderungen durch,<p>";
echo "betätigen Sie anschließend den Button<p>";
echo "<form action = 'uf16c.php' ";
echo " method = 'post'>";
echo "<input name='neunn' value='$altnn'>";
echo " Nachname<p>";
echo "<input name='neuvn' value='$altvn'> ";
echo " Vorname<p>";
echo "<input name='neupn' value='$auswahl'>";
echo " Personalnummer<p>";
echo "<input name='neuge' value='$altge'>";
echo " Gehalt<p>";
echo "<input name='neugt' value='$altgt'>";
echo " Geburtstag<p>";
echo "<input type='hidden' name='oripn' ";
echo " value='$auswahl'>";
echo "<input type='submit' ";
echo " value='Änderungen in DB speichern'><p>";
echo "<input type='reset'>";
echo "</form>";
mysql_close($db);
}
else
echo "Es wurde kein Datensatz ausgewählt<p>";
?>
</body>
</html>