benjahnee Posted March 20, 2013 Share Posted March 20, 2013 (edited) hello guys i have made a basic database in myadmin and i have written php code to connect to it. my database is called products. When i run the page i get the output - Connection Successful could not connect to products can somebody look at my code and tell me why i can not connect to my database <?php $host="localhost"; $user=""; $password=""; $db = "products"; $connect = mysql_connect($host, $user, $password); if($connect) { echo "Connection Successful"; $select = mysql_select_db($db); if ($select) { echo "<br /> connected to ".$db; } else { echo "<be /> could not connect to ".$db; } } else { echo "failed connection"; } ?> thankyou Edited March 23, 2013 by fenway code tags Quote Link to comment https://forums.phpfreaks.com/topic/275918-problem-connecting-to-databse/ Share on other sites More sharing options...
Barand Posted March 20, 2013 Share Posted March 20, 2013 are you sure the database name is "products" or is that your table name? Quote Link to comment https://forums.phpfreaks.com/topic/275918-problem-connecting-to-databse/#findComment-1419814 Share on other sites More sharing options...
benjahnee Posted March 20, 2013 Author Share Posted March 20, 2013 i called both the table and the database "products" would this cause a problem? Quote Link to comment https://forums.phpfreaks.com/topic/275918-problem-connecting-to-databse/#findComment-1419823 Share on other sites More sharing options...
Solution Barand Posted March 20, 2013 Solution Share Posted March 20, 2013 i called both the table and the database "products" would this cause a problem? No, that's ok. Are you sure you spelled it correctly when you created it? try SHOW DATABASES Quote Link to comment https://forums.phpfreaks.com/topic/275918-problem-connecting-to-databse/#findComment-1419922 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.