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.<br /><br />I have tried creating a query using myPHP with supplied code but I still get the "no database found" error. <br /><br />The code I am tying to get to work:<br /><br />mysql_connect ('local host', 'user', 'password') or die ("connect ". mysql_error());<br />mysql_select_db('cbost_usedcollector');<br />$query="select * from Unit where ".$searchtype." like "$searchterm.";<br />$result = mysql_query($query) or die("query" .mysql_error());<!--content-->
I noticed that I left off the final ' " ' on the query. So it is not a format error. I also tried:<br /><br />$query=" SELECT * FROM Unit WHERE Type like'$searchterm'";<!--content-->
Hi,<br /><br />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.<br /><br />Using DIE just quits the operation from the user end, it does not succesffully mean that you have talked to the database.<br /><br />Make sure you have some information in the database too!<br /><br />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<br /><br />Jim<!--content-->
<!--QuoteBegin-cdbost+Apr 4 2003, 10:01 AM--><div class='quotetop'>QUOTE(cdbost @ Apr 4 2003, 10:01 AM)</div><div class='quotemain'><!--QuoteEBegin-->mysql_select_db('cbost_usedcollector');<!--QuoteEnd--></div><!--QuoteEEnd--><br /> should that be cdbost instead of cbost?<!--content-->
You might try using mysql_error() to help you debug the problem - example here:<br /><a href="http://www.php.net/manual/en/function.mysql-error.php" target="_blank">http://www.php.net/manual/en/function.mysql-error.php</a><!--content-->
I noticed that I left off the final ' " ' on the query. So it is not a format error. I also tried:<br /><br />$query=" SELECT * FROM Unit WHERE Type like'$searchterm'";<!--content-->
Hi,<br /><br />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.<br /><br />Using DIE just quits the operation from the user end, it does not succesffully mean that you have talked to the database.<br /><br />Make sure you have some information in the database too!<br /><br />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<br /><br />Jim<!--content-->
<!--QuoteBegin-cdbost+Apr 4 2003, 10:01 AM--><div class='quotetop'>QUOTE(cdbost @ Apr 4 2003, 10:01 AM)</div><div class='quotemain'><!--QuoteEBegin-->mysql_select_db('cbost_usedcollector');<!--QuoteEnd--></div><!--QuoteEEnd--><br /> should that be cdbost instead of cbost?<!--content-->
You might try using mysql_error() to help you debug the problem - example here:<br /><a href="http://www.php.net/manual/en/function.mysql-error.php" target="_blank">http://www.php.net/manual/en/function.mysql-error.php</a><!--content-->