0

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>';
6
  • 2
    Just going to say, deleting by first name is a bad idea. Especially how at work I have an Adam for a boss, Adam for a coworker in support, Adam as a sysop, and I myself am Adam. What if I just want to delete one of them? Commented Dec 14, 2014 at 17:29
  • oh sure I'm going to change that in the next phase. I just wanted to get it up and running first Commented Dec 14, 2014 at 17:31
  • Do you get the proper HTML output? Is the firstname there in the form when you look at the source? And also, if you do "print_r($REQUEST)" on delete.php what do you get then? :) Commented Dec 14, 2014 at 17:32
  • I get the proper html output, I don't understand what you mean by the second question. On delete.php when I check if(isset($_POST['firstname'])) I get false Commented Dec 14, 2014 at 17:33
  • as csaw mentioned in his answer, method should be post, not the action twice. And @NiettheDarkAbsol has right also. Commented Dec 14, 2014 at 17:34

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

I would consider this a typo question, and therefore it should be closed, not answered - point out the typo in a comment ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.