Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[SOLVED]LXF 170 "The LAMP stack" Errors

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Magazine and coverdiscs
View previous topic :: View next topic  
Author Message
gdawg



Joined: Fri Nov 18, 2011 2:55 pm
Posts: 13
Location: New Mexico, USA

PostPosted: Tue Jul 16, 2013 5:02 pm    Post subject: [SOLVED]LXF 170 "The LAMP stack" Errors Reply with quote

Hi, while trying to run http://localhost/booksearch.html I get the following error
Quote:
Fatal error: Call to a member function bind_result() on a non-object in /var/www/html/booksearch.php on line 41 Call Stack: 0.0004 334840 1. {main}() /var/www/html/booksearch.php:0.
Here is the code:
Code:
  <!DOCTYPE html>
<html>
<head>
 <title>Library Book Search</title>
</head>
<body>
<h3>Book Search Results</h3><br>
<hr>
<?php
// Get data from form
$searchtitle = trim($_REQUEST['searchtitle']);
$searchauthor = trim($_REQUEST['searchauthor']);
if(!$searchtitle && !$searchauthor) {
 echo "You must specify either a title or an author";
 exit();
}
$searchtitle = addslashes($searchtitle);
$searchauthor = addslashes($searchauthor);


// Open the database
@ $db = new mysqli('localhost', 'root', '-t9m3s4e8d0*', 'library');
if($db->connect_error) {
        echo "could not connect:" .$db->connect_error;
        exit();
}
// Build the query. Users are allowed to search on title,
// author, or both
$query = "select * from books";
if($searchtitle && !$searchauthor) { // Title search only
 $query = $query . " where title like '%" . $searchtitle . "%'";
}
if(!$searchtitle && $searchauthor) { // Author search only
 $query = $query . " where author like '%" . $searchauthor . "%'";
}
if($searchtitle && $searchauthor) { // Title and Author search
  $query = $query . "where title like '%" . $searchtitle . "%'
and
author like '%" . $searchauthor . "%'"; // unfinished
}
// Run the query using bound result parameters
$stmt = $db->prepare($query);
$stmt->bind_result($bookid, $title, $author, $onloan, $duedate, $borrowerid);
$stmt->execute();
echo "<table border=1>";
while ($stmt->fetch()) {
  echo "<tr><td> $bookid </td> <td> $title </td><td> $author
</td></tr>";
I've copied the above code verbatim from the tutorial. Any help will be greatly appreciated.

_________________
Linux gdawg-Inspiron-530s 3.2.0-23-generic-pae #36-Ubuntu SMP Tue Apr 10 22:19:09 UTC 2012 i686 i686 i386 GNU/Linux


Last edited by gdawg on Wed Jul 17, 2013 5:33 pm; edited 1 time in total
Back to top
View user's profile Send private message
Ram
LXF regular


Joined: Thu Apr 07, 2005 10:44 pm
Posts: 1674
Location: Guisborough

PostPosted: Wed Jul 17, 2013 1:46 am    Post subject: Reply with quote

Quick glance, I can't see a closing tag for the php code.
Code:

<?php
?>

_________________

lubuntu LXDE 13.10 running on AMD Phenom II*4; ASUS Crosshair III Formula MB; 4 GB Ram.....
Back to top
View user's profile Send private message MSN Messenger
Ram
LXF regular


Joined: Thu Apr 07, 2005 10:44 pm
Posts: 1674
Location: Guisborough

PostPosted: Wed Jul 17, 2013 2:52 pm    Post subject: Reply with quote

Your code appears to be missing the last 5 lines of code.

Code:

}
echo "</table>";
?>
</body>
</html>

_________________

lubuntu LXDE 13.10 running on AMD Phenom II*4; ASUS Crosshair III Formula MB; 4 GB Ram.....
Back to top
View user's profile Send private message MSN Messenger
gdawg



Joined: Fri Nov 18, 2011 2:55 pm
Posts: 13
Location: New Mexico, USA

PostPosted: Wed Jul 17, 2013 5:28 pm    Post subject: Reply with quote

Thank you Ram. You're correct I failed to copy & paste the code correctly when I posted it.
Code:
}
echo "</table>";
?>
</body>
</html>

It's there but I missed it.
Code:
<!DOCTYPE html>
<html>
<head>
 <title>Library Book Search</title>
</head>
<body>
<h3>Book Search Results</h3><br>
<hr>
<?php
// Get data from form
$searchtitle = trim($_REQUEST['searchtitle']);
$searchauthor = trim($_REQUEST['searchauthor']);
if(!$searchtitle && !$searchauthor) {
 echo "You must specify either a title or an author";
 exit();
}
$searchtitle = addslashes($searchtitle);
$searchauthor = addslashes($searchauthor);
// Open the database
@ $db = new mysqli('localhost', 'root', '-t9m3s4e8d0*', 'library');
if($db->connect_error) {
   echo "could not connect:" .$db->connect_error;
   exit();
}
// Build the query. Users are allowed to search on title,
// author, or both
$query = "select * from books ";
if($searchtitle && !$searchauthor) { // Title search only
 $query = $query . " where title like '%" . $searchtitle . "%'";
}
if(!$searchtitle && $searchauthor) { // Author search only
 $query = $query . " where author like '%" . $searchauthor . "%'";
}
if($searchtitle && $searchauthor) { // Title and Author search
  $query = $query . "where title like '%" . $searchtitle . "%'
and
author like '%" . $searchauthor . "%'"; // unfinished
}
// Run the query using bound result parameters
$stmt = $db->prepare($query);
$stmt->bind_result($bookid, $title, $author, $onloan, $duedate, $borrowerid);
[b]echo $db->error;[/b]
$stmt->execute();
echo "<table border=1>";
while ($stmt->fetch()) {
  echo "<tr><td> $bookid </td> <td> $title </td><td> $author
</td></tr>";
}
echo "</table>";
?>
</body>
</html>

It's working now since I added

Quote:
echo $db->error;
I don't know why. I don't see any errors being revealed. Thanks for your help.

_________________
Linux gdawg-Inspiron-530s 3.2.0-23-generic-pae #36-Ubuntu SMP Tue Apr 10 22:19:09 UTC 2012 i686 i686 i386 GNU/Linux
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Magazine and coverdiscs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast