I have a button that generates after each table row is generated in the loop, the name of each consecutive button is generated by $a++ variable. How do i use the $_POST method on my edit_contact.php page so i can use the variable from the $_POST array?
The variable is stored in the $_POST array, i have checked with Print_r($_POST); for example when i click on the third row edit button of the table, it will display as:
Array ( [3] => edit )
Here is the code of the loop on my list_contact.php page:
$a = "0";
// print whether success or not
if ($rst)
{
if (mysql_num_rows($rst)>0) // chech there are records
{
echo "<form name=addcontact method=post action=edit_contact.php>";
echo "<table border=\"1\" cellspacing=\"0\">";
/*** print out feild names ***/
while ($row = mysql_fetch_array($rst)) // fetch each row
{
echo "<tr>";
for ($i=0; $i<mysql_num_fields($rst); $i++) //for ech row print out field values
{
echo "<td>" . $row[$i] . "</td>";
}
echo "<td>" . "<input id=button type=submit name=" . $a++ . " value=Edit" . "</td>";
echo "</tr>";
}
echo "</table>";
echo "</form>";
}
else
{
echo "There are no records in the database";
}
}
And here is the code i am having trouble with on my edit_contact.php:
$qry = "SELECT * FROM contacts WHERE ContactID = " . $_POST;
How can i get that post to reflect just my variable? ie 3
mysql_num_rowsand other mysql functions are deprecated. Try using themysqliextension orPHP Data Objects (PDO)