PostgreSQL & PHP Tutorials - Updating entries in your database
Viewing page 1 of 2
« | Back |
Next |
»
How do we update information already in our database? Here's a look at it.
We'll use the fetch page as a starting point:
<html>
<body>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
Friend ID
</td>
<td>
First Name
</td>
<td>
Surname
</td>
<td>
Email Address
</td>
</tr>
<?php
$db = pg_connect('host=localhost dbname=contacts user=contacts password=firstphp');
$query = "SELECT * FROM friends";
$result = pg_query($query);
if (!$result) {
echo "Problem with query " . $query . "<br/>";
echo pg_last_error();
exit();
}
while($myrow = pg_fetch_assoc($result)) {
printf ("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>", $myrow['id'], htmlspecialchars($myrow['firstname']), htmlspecialchars($myrow['surname']), htmlspecialchars($myrow['emailaddress']));
}
?>
</table>
<br/>
<form action="update.php" method="post">
ID to Update : <input type="text" name="id" size="4" length="4" value="ID"><br>
First Name : <input type="text" name="firstname" size="40" length="40" value="First Name"><br>
Surname to update : <input type="text" name="surname" size="40" length="40" value="Surname"><br>
<input type="submit" name="submit" value="Update It">
<input type="reset" name="reset" value="Clear It">
</form>
</body>
</html>
This is our form that "updates" the information.
In this example, we're updating the first name, and the surname for the ID that we type in.
*Note, we're displaying the database as well so that we can find what we want to update easily - this isn't normally done*.
It passes what we type in the form to the "update" script.
Viewing page 1 of 2
« | Back |
Next |
»
Avg Rating: 5
Vote Count: 2
