ziad Posted April 30, 2013 Share Posted April 30, 2013 Hi guys, I am trying to run the code below and I end up getting the error above, as am a newby in php, i just can't figure out where am going wrong, can anyone help me please <?php require "db3.inc";// 1.open the database connection - always use localhost $connection = mysql_connect($hostname, $username, $password); //2. Open the database connection and use the winestore database mysql_select_db($dbname, $connection); $query = "SELECT * FROM product"; $ProductType = $_GET["ProductType"] ; //Create the Query $query = "SELECT * FROM product "; // ... then, if the user has specified a type , // add the regionName as an AND clause ... if ($ProductType != 1) // Note the literals around $windType $query .= " WHERE Make = '$ProductType'"; // ... and then complete the query. $query .= " ORDER BY Make "; //Get the recordset $result = mysql_query($query,$connection) OR die(mysql_error($query)); $num_rows = mysql_num_rows($result); //Check some records have been found if ($num_rows < 1 ) { echo "<strong> No Products found - make sure you entered the Product name correctly</strong>"; } else //Format the information into a table using table/cell tags while ($row = @ mysql_fetch_row($result)) { // ... start a Table row... echo "\n<tr>"; // ... and print out each of the attributes in that row as // seperate TD (table Date) foreach($row as $data) print "\n\t<td> {$data} </td>"; // finish the row print "\n<tr>"; } // then finish the table print "\n</table>\n";// (5) Close the connectionmysql_close($connection);?></table></body></html> Quote Link to comment Share on other sites More sharing options...
oaass Posted April 30, 2013 Share Posted April 30, 2013 $query is a string, $connection is a resource From the manual string mysql_error ([ resource $link_identifier = NULL ] ) Try this instead $result = mysql_query($query,$connection) OR die(mysql_error($connection)); I do strongly advice you to stop using the mysql extension and look at mysqli and/or PDO instead.. See my signature for the reason Quote Link to comment Share on other sites More sharing options...
ziad Posted May 1, 2013 Author Share Posted May 1, 2013 Thanks for your suggestion oaass, Changing the $query string into the $connection Resource eliminated the error, but it created a new error saying "NO DATABASE SELECTED". Quote Link to comment Share on other sites More sharing options...
DavidAM Posted May 1, 2013 Share Posted May 1, 2013 Please use CODE tags when posting code: That error would indicate that you have not selected a database. Back at the beginning of the code you have: //2. Open the database connection and use the winestore database mysql_select_db($dbname, $connection); add the or die(mysql_error()); to that statement to see why the database selection is failing. Either the database does not exist, or the user does not have access to it, or the variable is not defined, or something. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.