OK,
I have an id as increment, but I still have a problem. I was able to delete when click on the delete link, but when I click on the update, I've got the error. here's my code:
<?php
$hostname = "localhost";
$username = "root";
$password = "Passw0rd";
$conn = mysql_connect($hostname, $username, $password) or die ("mysql error");
$selected = mysql_select_db("first_test",$conn) or die ("database error");
// delete record
$delete_record = $GET['delete'];
if (isset($GET['delete']))
{
mysql_query("delete from people where id = '$delete_record'");
echo $delete_record . ' was deleted!<p>';
}
// display result
$result = mysql_query("select * from people order by id");
echo "<table border = '1' align='center' width='70%'>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Phone Number</th>
<th>Delete Record</th>
<th>Update Record</th>
</tr>";
while ($row = mysql_fetch_assoc($result))
{
echo '<tr>
<td> '.$row['id']. '</td>
<td> '.$row['first_name']. '</td>
<td> '.$row['last_name']. '</td>
<td> '.$row['ph_no']. '</td>
<td><a href="delete.php?delete= ' .$row['id']. '">Delete</td>
<td><a href="update-form.php?= ' .$row['id']. '">Edit</td>
</tr>';
}
echo '</table>';
echo "<p><a href='test.php'>View Record</a>";
mysql_close($conn);
?>
// Here's the update form..
<?php
$hostname = "localhost";
$username = "root";
$password = "Passw0rd";
$db = mysql_connect($hostname, $username, $password) or die ("not able to connected to mysql");
// connect to database
$select = mysql_select_db("first_test",$db) or die (" not able connected to db");
$update = $_GET['id'];
$result = mysql_query("select * from people where id = $update");
$row = mysql_fetch_assoc($result);
mysql_close($db);
?>
<form action="update.php" method="post">
ID: <input type="text" name="id" value="<?php echo $row["id"] ?>" />
FirstName: <input type="text" name="first_name" value="<?php echo $row["first_name"]?>" />
<br />
LastName: <input type="text" name="last_name" value="<?php echo $row["last_name"] ?>" />
<br />
Phone#: <input type="text" name="ph_no" value="<?php echo $row["ph_no"] ?>" />
<br />
<br />
<input type="submit" name="submit" />
</form>