Hi,
Hopefully this is the final post about the code below: I have post elsewhere in the past in order to bring my understanding up to speed.
Will the following code that I put together help combat SQL INJECTION:
// DATABASE FUNCTION //Search database for pages matching the current
// page and display the title, description and keywords
$page = isset($_GET['page']) ? $_GET['page'] : 'home';
//$page = $mysqli->real_escape_string($page);
if($stmt = $mysqli -> prepare("SELECT * FROM url WHERE page=? LIMIT 1")) {
$stmt -> bind_param("s",$page);
$stmt -> execute();
$stmt -> fetch();
}
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$sql = $stmt;
if ($sql->num_rows > 0) {
while ($row = $sql->fetch_object())
{
$title = $row->title;
$description = $row->descr;
$keywords = $row->keywords;
}
} else {
$title = 'Set Default Title';
$description = 'Set Default Description';
$keywords = 'Set Default Keywords';
$stmt -> close();
}
$mysqli -> close();