5 messages in com.mysql.lists.win32Re: PHP code query.| From | Sent On | Attachments |
|---|---|---|
| joh...@net2000.com.au | 27 Nov 2004 04:53 | |
| Janet Valade | 27 Nov 2004 11:43 | |
| Eve Atley | 27 Nov 2004 12:38 | |
| John Bonnett, R&D Australia | 29 Nov 2004 14:10 | |
| John Fitzsimons | 04 Dec 2004 15:55 |
| Subject: | Re: PHP code query.![]() |
|---|---|
| From: | Eve Atley (eat...@wow-corp.com) |
| Date: | 11/27/2004 12:38:11 PM |
| List: | com.mysql.lists.win32 |
After your $sql variable, you'll need to perform the query using:
mysql_query($sql);
..to actually get it to return anything.
- Eve
joh...@net2000.com.au wrote:
Hi,
I try an SQL query in phpMyAdmin and it works okay. I am also given a connection string in PHP as well. When I try to combine these into a .PHP page to query the database it doesn't work. No error. Nothing.
I am obviously doing something wrong but I don't know what. My database and table have the same name but I hope that doesn't matter. Apart from changing my password/username below, this is what I tried ;
<html> <body> <?php $dbh=mysql_connect ("localhost", "jf_USER", "password") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("jf_invcomma"); $sql = 'SELECT ' . ' `invcomma`.`ISBN`,' . ' `invcomma`.`TITLE`,' . ' `invcomma`.`AUTHOR`,' . ' `invcomma`.`PRICE`,' . ' `invcomma`.`CAT`' . ' FROM' . ' `invcomma`' . ' WHERE' . ' `invcomma`.`AUTHOR` = "Hall Judy" ' . ' ORDER BY' . ' `invcomma`.`ISBN`,' . ' `invcomma`.`TITLE`,' . ' `invcomma`.`AUTHOR`,' . ' `invcomma`.`PRICE`,' . ' `invcomma`.`CAT` LIMIT 0, 30'; ?> </body>
Can anyone tell me what I have done wrong and/or the correct code to make things work please ?
I'm not sure what you are trying to do. Your code above connects to MySQL and selects a database. Then, you save an SQL query in a variable named $sql. That's all you do. You have no instruction that produce any output, so you don't get any output.
I suggest that you first echo your SQL query to see that it is as you expect. (echo $sql) This is a debugging statement to be removed later once everything is working.
Once your SQL looks as it should, you need to execute it using a mysql_query function. This will put the records selected into a temporary result set. Then, you need to display the records in the result set on your web page. You can look at the example at http://www.php.net/manual/en/ref.mysql.php.
Janet
Regards, John.




