A2enMOD Posted January 6, 2013 Share Posted January 6, 2013 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 https://forums.phpfreaks.com/topic/272777-code-not-extracting-data-from-db/ Share on other sites More sharing options...
Barand Posted January 6, 2013 Share Posted January 6, 2013 check for error after executing the query Link to comment https://forums.phpfreaks.com/topic/272777-code-not-extracting-data-from-db/#findComment-1403759 Share on other sites More sharing options...
A2enMOD Posted January 7, 2013 Author Share Posted January 7, 2013 check for error after executing the query So I dont understand what you mean? Link to comment https://forums.phpfreaks.com/topic/272777-code-not-extracting-data-from-db/#findComment-1403787 Share on other sites More sharing options...
Christian F. Posted January 7, 2013 Share Posted January 7, 2013 This post will help you: http://forums.phpfreaks.com/index.php?topic=365029.msg1730174#msg1730174 Link to comment https://forums.phpfreaks.com/topic/272777-code-not-extracting-data-from-db/#findComment-1403793 Share on other sites More sharing options...
Barand Posted January 7, 2013 Share Posted January 7, 2013 $res = $stmt->execute(); if (!$res) die($stmt->error); Link to comment https://forums.phpfreaks.com/topic/272777-code-not-extracting-data-from-db/#findComment-1403794 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.