List:MySQL on Win32« Previous MessageNext Message »
From:Janet Valade Date:November 27 2004 7:43pm
Subject:Re: PHP code query.
View as plain text  
johnf@stripped 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.
> 
> 


-- 
Janet Valade -- janet.valade.com

Thread
PHP code query.johnf27 Nov
  • Re: PHP code query.Janet Valade27 Nov
    • Re: PHP code query.Eve Atley27 Nov
    • Re: PHP code query.John Fitzsimons5 Dec
RE: PHP code query.R&D Australia John Bonnett29 Nov