cdbost Posted April 4, 2003 Share Posted April 4, 2003 I have set up a database using the Mysql interface provided on the control panel. I can query the database without any trouble using the SQL dialog. I am new(very) to using PHP and I have a nifty book here and I am trying to learn it. I have tried the example provided by the book but I get a "no database found" error on the query. I believe I have opened the database without any problems because I use the $dbh=mysql_connect() or die and I do not receive any errors. I have tried creating a query using myPHP with supplied code but I still get the "no database found" error. The code I am tying to get to work: mysql_connect ('local host', 'user', 'password') or die ("connect ". mysql_error()); mysql_select_db('cbost_usedcollector'); $query="select * from Unit where ".$searchtype." like "$searchterm."; $result = mysql_query($query) or die("query" .mysql_error()); Quote Link to comment Share on other sites More sharing options...
cdbost Posted April 4, 2003 Author Share Posted April 4, 2003 I noticed that I left off the final ' " ' on the query. So it is not a format error. I also tried: $query=" SELECT * FROM Unit WHERE Type like'$searchterm'"; Quote Link to comment Share on other sites More sharing options...
TCH-JimE Posted April 4, 2003 Share Posted April 4, 2003 Hi, Best thing to do with a database is actually just to pull out some information first to see whether you can contact and talk to the database ok. Using DIE just quits the operation from the user end, it does not succesffully mean that you have talked to the database. Make sure you have some information in the database too! Last thing, check on the publisher book site to make sure there are no errors, because some computer books have errors that are corrected on the website Jim Quote Link to comment Share on other sites More sharing options...
baseline Posted April 4, 2003 Share Posted April 4, 2003 mysql_select_db('cbost_usedcollector'); should that be cdbost instead of cbost? Quote Link to comment Share on other sites More sharing options...
jasonsho Posted April 4, 2003 Share Posted April 4, 2003 You might try using mysql_error() to help you debug the problem - example here: http://www.php.net/manual/en/function.mysql-error.php 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.