简体   繁体   中英

Passing PHP variable through html form

Hello I'm trying to make a telephone contacts list using PHP and MySQLi.

This part of the program should display a list of all contacts with a delete button next to each row. Pressing the delete button should pass the $firstname value to another page and then do some further MySqli processing.

For some reason, the $firstname variable does not get passed on to the next page.

$results = $db->query("SELECT first_name, last_name, tele FROM contacts");

// Column headings
print '<table border="1">';
print '<tr>';
print '<td>First name</td>';
print '<td>Last name</td>';
print '<td>Telephone number</td>';

while($row = $results->fetch_object()) {
    $firstname = $row->first_name;
    print '<tr>';
    print '<td>'.$firstname.'</td>';
    print '<td>'.$row->last_name.'</td>';
    print '<td>'.$row->tele.'</td>';
    print '<td>
           <form action="delete.php" action="POST">
                <input type="hidden" name="firstname" value="'.$firstname.'">
                <input type="submit" value="Delete">
           </form>
           </td>
           </tr>';
}

print '</table>';

change <form action="delete.php" action="POST"> to <form action="delete.php" method="POST">

to consider, maybe put checkbox next to items to delete. then on submit delete multiple items

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM