Jump to content

Mysql Query With Php


cdbost

Recommended Posts

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());

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...