Jump to content

Code not extracting data from DB


A2enMOD

Recommended Posts

Hi guys,

 

I am having trouble with the following code that I put together. It is not getting any data from the DB, can you see if I have made any errors in my syntax?

 

// DATABASE FUNCTION //Search database for pages matching the current
// page and display the title, description and keywords


$page = isset($_GET['page']) ? $_GET['page'] : 'home';



if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}


if($stmt = $mysqli->prepare("SELECT * FROM url WHERE page=? LIMIT 1")) {


$stmt -> bind_param("s",$page);


$stmt -> execute();


$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();

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.