kagster Posted June 16, 2009 Share Posted June 16, 2009 Please can someone help? I have set up this query but keep gettin this error Warning: mysqli_error() expects parameter 1 to be mysqli, resource given in C:\wamp\www\KidsCorner\search_results.php on line 46 Query: SELECT t.BtName, a.AuthorName, p.PubName FROM author AS a INNER JOIN authorship AS i USING (AuthorId) INNER JOIN BookTitle AS t USING (BtId) INNER JOIN publisher AS p USING (PubId) WHERE a.AuthorName LIKE '% Warning: mysqli_close() expects parameter 1 to be mysqli, resource given in C:\wamp\www\KidsCorner\search_results.php on line 50 I'm presuming there is something wrong with the way I have done my query, as it is not working Below is my code for my search form: <br> Please enter the title of the book you wish to search for:<br /> <br /> <form action="search_results.php" method="post" name="findBook" id="findBook" class="finderForm"> <p><label>Book title:</label><input type="text" name="BtName" value="<?echo $_POST["BtName"]?>" class="field" size="20" /></p> <p><label>Author:</label><input type="text" name="AuthorName" value="<?echo $_POST["AuthorName"]?>" class="field" size="20"/></p> <p><label>Publisher:</label><input type="text" name="PubName" value="<?echo $_POST["PubName"]?>" class="field" size="20"/></p> <p class="btn"><input type="submit" name="submit" value="Search BookWormz.." /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> <? if (isset($_POST['submitted'])) { // Check form has been Submitted IF // If it has process the search: include("search_results.php"); ?> <? } else { // If the form has not been submitted. ?> HERE IS MY CODE FOR MY RESULTS PAGE: <?php $page_title = 'Search Library!'; include ('includes/header.html'); ?> <?php $dbc = mysql_connect ("localhost", "root","mudder") or die (mysql_error()); mysql_select_db ("childrens_library"); //$sql = mysql_query("select * from BookTitle where BtName like '%$searchterm%'"); $query = "SELECT t.BtName, a.AuthorName, p.PubName FROM author AS a INNER JOIN authorship AS i USING (AuthorId) INNER JOIN BookTitle AS t USING (BtId) INNER JOIN publisher AS p USING (PubId) WHERE a.AuthorName LIKE '%".$_POST["AuthorName"]."%' AND p.PubName LIKE '%".$_POST["PubName"]."%' AND t.BtName LIKE '%".$_POST["BtName"]."%'"; $row = @mysqli_query ($dbc, $query); // Run the query. if ($row) { // If it ran OK, display the records. // Table header. echo '<table cellspacing="0" cellpadding="0">'; echo '<tr><td><b>Book Title</b></td>'; echo '<td><b>Author</b></td>'; echo '<td><b>Publisher</b></td></tr>'; // Fetch and print all the records: while ($row = mysqli_fetch_array($row, MYSQLI_ASSOC)) { echo '<tr><td>' . $row['BtName'] . '</td>'; echo '<td>' . $row['AuthorName'] . '</td>'; echo '<td>' . $row['PubName'] . '</td></tr>'; } echo '</table>'; // Close the table. mysqli_free_result ($row); // Free up the resources. } else { // If it did not run OK. // Public message: echo '<p>The book(s) you were looking for cannot be found. We apologize for any inconvenience.<br /><br />'; // Debugging message: echo mysqli_error($dbc) . '<br /><br />Query: ' . $query . '</p>'; } // End of if ($row) IF. mysqli_close($dbc); // Close the database connection. Please can someone tell me where I am going wrong? Many thanks Paul Link to comment https://forums.phpfreaks.com/topic/162447-helpphp-error-with-mysql-query-newbie/ Share on other sites More sharing options...
Ken2k7 Posted June 17, 2009 Share Posted June 17, 2009 If you have a mysql connection, why are you using mysqli functions? Stick with one or the other, not both. Link to comment https://forums.phpfreaks.com/topic/162447-helpphp-error-with-mysql-query-newbie/#findComment-857738 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.