Hey all, I'm learning how to use mySQL reading a book called 'PHP and MySQL Web Development' by Luke Welling & Laura Thomson. I'm working through an example but have become stuck! I've set up the database on my server hosted by streamline.net which looks like this;Customers(CustomerID, Name, Address, City)Orders(OrderID, CustomerID, Amount, Date)Books(ISBN, Author, Title, Price)Order_Items(OrderID, ISBN, Quantity)Book_Reviews(ISBN, Reviews)I then setp up a small form on a web page to query this database.
<form id="search" action="results.php" method="post"> <p> <label for="searchtype">Search by: </label> <select name="searchtype" id="searchtype"> <option value="author">Author</option> <option value="title">Title</option> <option value="isbn">ISBN</option> </select> </p> <p> <label for="searchterm">Search term: </label> <input name="searchterm" id="searchterm" type="text" /> </p><p> <input type="submit" id="submit" value="Search" /> </p></form>
But the code in my php file doesn't seem to be connecting to the database.
<?php //create short variable names $searchType = $_POST['searchtype']; $searchTerm = $_POST['searchterm']; $searchTerm = trim($searchTerm); if (!$searchType || !$searchTerm) { echo 'You have not entered search details. Please go back and try again.'; exit; } if (!get_magic_quotes_gpc()) { $searchType = addslashes($searchType); $searchTerm = addslashes($searchTerm); } @ $db = mysqli_connect('mysql8.streamline.net', 'tomcootec', 'mypassword', 'tomcootec'); if (mysqli_connect_errno()) { echo 'Error: Could not connect to database. Please try again later.'; exit; } $query = "select * from books where ".$searchType." like '%".searchTerm."%'"; $results = mysqli_query($db, $query); $num_results = mysqli_num_rows($results); echo '<p>Number of books found: '.$num_results.'</p>'; for ($i=0; $i < $num_results; $i++) { $row = mysqli_fetch_assoc($results); echo '<p><strong>'.($i+1).'Title: '; echo htmlspecialchars(stripslashes($row['title'])); echo '</strong><br />Author: '; echo stripslashes($row['author']); echo '<br />ISBN :'; echo stripslashes($row['isbn']); echo '<br />Price: '; echo stripslashes($row['price']); echo '</p>'; } mysqli_free_result($results); mysqli_close($db);?>
If I take away the error suppression operator '@' from the line when connecting i get the following error.
Can anyone give me some help on this one?Thanks- Tom