PHP Code:
require "config.php";
// find id (this assumes that the query string variable is named 'id':
$id = $_GET['id'];
// make sure id is a number, and safeguard against an sql injection
if (!preg_match("#^\d+$#", $id)) {
// maybe die here with an error
}
// one SQL statement
$query= "SELECT * FROM diary_contents WHERE id = '$id'";
// one call to mysql_query
$r= mysql_query($query) OR die('Query error: ' .mysql_error());
// make sure the entry was found
if (mysql_num_rows($r) == 0) {
// no entry with this id found, maybe die here with an error
}
// one call to fetch the resultset
$row= mysql_fetch_assoc($r);
// display the date info
echo $row['selectDay'].'-'.$row['selectMonth'].'-'.$row['selectYear'].'<br />';
// display the record data
echo '<textarea name="diary_entry" cols="30" rows="5" id="diary_entry">'.$row['diary_entry'].'</textarea>';
mysql_close();
Bookmarks