lundi 1 juin 2015

Updating database using links and textboxes

I have a database that displays the data in three rows. Firstname, Lastname, and Age. I have it display in separate text boxes, as shown below.

Add entry totally works. No problems there. The real problem is the "Update" and "Delete" links. Keep in mind that buttons do work, but I'm not suppose to use buttons. When I click delete, the entry does in fact delete. And the whole row with the boxes and update and delete are gone.

The problem is that when I click Update after filling in the boxes with other data, this happens.

Here is the code that I use (at least the important bits)

PHP:

if($_GET['type']=='delete'){
                    $sql = "DELETE FROM addresses WHERE id ='$_GET[id]'";
                    mysql_query($sql,$conn);
                    header("Location: form.php");
}if ($_GET['type']=='update'){
                //works but it doesn't seem to just update like before.
                $sql = "UPDATE addresses SET firstname='$_GET[firstname]', lastname='$_GET[lastname]', age='$_GET[age]' WHERE id='$_GET[id]'";
                mysql_query($sql,$conn);
                header("Location: form.php");
}

And here is the HTML to do the table and links.

<?php
while($row = mysql_fetch_array($retreve, MYSQL_ASSOC)){

//echo"<form action='form.php' method='post' name='form'>";
echo "<tr>";
echo "<td><input type='text' name='firstname' value='".$row['firstname']."'> </td>";
echo "<td><input type='text' name='lastname' value='".$row['lastname']."'> </td>";
echo "<td><input type='text' name='age' value='".$row['age']."'> </td>";
echo "<td><input type='hidden' name='id' value='".$row['id']."'> </td>";
//links insead of buttons
echo "<td><a href = 'form.php?type=update&id={$row['id']}&age={$_GET['age']}' id='update'> Update</a> </td>";
echo "<td><a href = 'form.php?type=delete&id={$row['id']}' id='delete'> Delete</a> </td>";
echo"</form>";
}
echo "</table>";

What am I doing wrong for the update message?

PS. It won't let me post more than two pictures. Or pictures.




Aucun commentaire:

Enregistrer un commentaire