467,922 Members | 1,328 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,922 developers. It's quick & easy.

What is Call to a member function?

32bit
What is Call to a member function bind_param() on bool in /file.php:60 n the context of the following code, and how do I fix it?

The Code:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Start PHP Session, if not already started. Login verification script will be placed in this section later.
  3. session_start();
  4. // Connect to database. Change this to the proper SQL connection info.
  5. $DATABASE_HOST = 'localhost';
  6. $DATABASE_USER = 'user';
  7. $DATABASE_PASS = 'password';
  8. $DATABASE_NAME = 'library';
  9.  
  10. // Try and connect using the info above. Return error if unsucessful.
  11. $con = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);
  12. if ( mysqli_connect_errno() ) {
  13.     // If there is an error with the connection, stop the script and display the error.
  14.     die('Failed to connect to MySQL: ' . mysqli_connect_error());
  15. }
  16.  
  17. // Now we check if the data from the lookup form was submitted, isset() will check if the data exists.
  18. if ( !isset($_POST['call']) ) {
  19.     // Could not get the data that should have been sent.
  20.     die('Please fill in a valid Call Number!');
  21. }
  22.  
  23. //Start HTML5 code for the output
  24. echo '<!DOCTYPE html>';
  25. echo '<head>';
  26. echo '<style>';
  27. echo 'table {';
  28. echo 'font-family: arial, sans-serif;';
  29. echo 'border-collapse: collapse;';
  30. echo 'width: 100%;';
  31. echo '}';
  32. echo 'td, th {';
  33. echo 'border: 1px solid #dddddd;';
  34. echo 'text-align: left;';
  35. echo 'padding: 8px;';
  36. echo '}';
  37. echo 'tr:nth-child(even) {';
  38. echo 'background-color: #dddddd;';
  39. echo '}';
  40. echo '</style>';
  41. echo'</head>';
  42. echo '<body>';
  43. echo '<table><tr>';
  44. echo '<th>Call No.</th>';
  45. echo '<th>Subject</th>';
  46. echo '<th>Title</th>';
  47. echo '<th>Author</th>';
  48. echo '<th>Description</th>';
  49. echo '<th>Publisher</th>';
  50. echo '<th>Year Pub.</th>';
  51. echo '<th>Year Rev.</th>';
  52. echo '<th>Cheked Out</th>';
  53. echo '</tr>';
  54.  
  55. // Prepare our SQL, preparing the SQL statement will prevent SQL injection. call is a Call No.
  56. // e.g. in the format 320.01SIM ,etc.
  57. $stmt = $con->prepare('SELECT * FROM catalog WHERE call = ?');
  58.  
  59. // Bind parameters (s = string, i = int, b = blob, etc), in our case the call number is a varchar string so we use "s"
  60.     $stmt->bind_param('s', $_POST['call']);
  61.  
  62. //Execute the prepared statement
  63.     $stmt->execute();
  64.     $result = $stmt->get_result();
  65.  
  66. // Loop through the rows of the table that match the result and output to html table.
  67.     while($row = $result->fetch_assoc()) {
  68.       echo "<tr><td>" . $row['call'] . "</td><td>" . $row['subject'] . "</td><td>" . $row['title'] . "</td><td>" . $row['author'] . "</td><td>" . $row['description'] . "</td><td>" . $row['publisher'] . "</td><td>" . $row['pubyear'] . "</td><td>" . $row['revision'] . "</td><td>" . $row['out'] . "</td></tr>";
  69.         }
  70.  
  71. //Close the SQL connection.        
  72.     $stmt->close();
  73.  
  74. //Finish up HTML5 code and exit this script.
  75. echo '</table></body></html>';
  76. exit;
  77. ?>
  78.  
2 Weeks Ago #1

✓ answered by Dormilich

I'd suspect that call is a reserved keyword.

  • viewed: 1842
Share:
5 Replies
Dormilich
Expert Mod 8TB
in line 57 $con->prepare() encounters an error and returns false. Hence the error.
1 Week Ago #2
32bit
That would seem to mean there's something wrong with the statement:

Expand|Select|Wrap|Line Numbers
  1.  ('SELECT * FROM catalog WHERE call = ?') 
Other than that, I can't see any reason it would return "false". Of course some of the database fields do contain rather large chunks of data, which makes me wonder if SQL is even the right device to use for what I'm trying to do.
1 Week Ago #3
Dormilich
Expert Mod 8TB
I'd suspect that call is a reserved keyword.
1 Week Ago #4
32bit
That turned out to be the problem. had to change both "call" and "out" in the SQL table because of them being reserved keywords. Thanks a bunch.
1 Week Ago #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

37 posts views Thread by Ben | last post: by
2 posts views Thread by dmitry.freitor | last post: by
5 posts views Thread by Tony Johansson | last post: by
18 posts views Thread by tbringley | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.