eldan88 Posted October 21, 2012 Share Posted October 21, 2012 Hey, It took to couple months to learn PHP and I am trying to extend my knowledge by designing my own ecommerce CMS. I am having difficulties with the building blocks. When I try to run a mySQL query I get the following message: "mysql_query(): 4 is not a valid MySQL-Link resource in" What does this mean and how can I solve this. Btw my connection is successful to the DB. Below is my cose <?php // Return data from the DB $query = "SELECT * FROM ecommerce "; $result = mysql_query($query,$connection); if(!$result) { die("mySQL DB read failed" . mysql_error()); } //use the return data while($return = mysql_fetch_array($result)) { $return['category_name']; } ?> <?php mysql_close($connection); ?> Any help is apperciated. Thanks! Quote Link to comment Share on other sites More sharing options...
iversonm Posted October 21, 2012 Share Posted October 21, 2012 Where is your connection variable? Quote Link to comment Share on other sites More sharing options...
eldan88 Posted October 23, 2012 Author Share Posted October 23, 2012 Where is your connection variable? Hey, Here is my connection variables located <?php require_once("constants.php")// This has all the constants for the DB connection ?> <?php // First you make a connection with the database $connection = mysql_connect(DB, username); if (!$connection) { die ( "Could not connect" . mysql_error()); } // Second you delect which DB you want to work with // You want to pass along the "handle to mysql_db_select" $db = mysql_select_db(db_name, $connection); if (!$db) { die("Couldn't Select a DB" . mysql_error()); } mysql_close($connection); Below is my constant file <?php define("DB", "localhost"); define("username", "root"); define("db_name", "ecommerce"); ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 23, 2012 Share Posted October 23, 2012 You see where you close the connection? Stop that. Bad coder. Quote Link to comment Share on other sites More sharing options...
Christian F. Posted October 23, 2012 Share Posted October 23, 2012 Also, you're not using a password, for the root user? Seriously? If, go set a password immediately. Even if it's just your development/test server. Quote Link to comment Share on other sites More sharing options...
eldan88 Posted October 23, 2012 Author Share Posted October 23, 2012 You see where you close the connection? Stop that. Bad coder. Hey, i removed the closed connection on my connection file, and it solved the issue. Thanks a lot for pointing that out! Quote Link to comment Share on other sites More sharing options...
eldan88 Posted October 23, 2012 Author Share Posted October 23, 2012 Also, you're not using a password, for the root user? Seriously? If, go set a password immediately. Even if it's just your development/test server. Hey. This is just a testing website. It will never be deployed in a publicly, and there isnt any kind of sensitive data. Thats why there isn't any password set. 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.