PHP code query.

PHP code query.

am 27.11.2004 13:54:15 von johnf

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 ;



$dbh=3Dmysql_connect ("localhost", "jf_USER", "password") or die ('I
cannot connect to the database because: ' . mysql_error());
mysql_select_db ("jf_invcomma");
$sql =3D 'SELECT '
. ' `invcomma`.`ISBN`,'
. ' `invcomma`.`TITLE`,'
. ' `invcomma`.`AUTHOR`,'
. ' `invcomma`.`PRICE`,'
. ' `invcomma`.`CAT`'
. ' FROM'
. ' `invcomma`'
. ' WHERE'
. ' `invcomma`.`AUTHOR` =3D "Hall Judy" '
. ' ORDER BY'
. ' `invcomma`.`ISBN`,'
. ' `invcomma`.`TITLE`,'
. ' `invcomma`.`AUTHOR`,'
. ' `invcomma`.`PRICE`,'
. ' `invcomma`.`CAT` LIMIT 0, 30';
?>


Can anyone tell me what I have done wrong and/or the correct code to
make things work please ?

Regards, John.


--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=3Dgcdmw-win32@m.gmane.org

Re: PHP code query.

am 27.11.2004 20:43:31 von Janet Valade

johnf@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 ;
>
>
>
> > $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';
> ?>
>
>
> 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


--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=gcdmw-win32@m.gmane.org

Re: PHP code query.

am 27.11.2004 21:38:33 von Eve Atley

After your $sql variable, you'll need to perform the query using:

mysql_query($sql);

...to actually get it to return anything.

- Eve


> johnf@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 ;
>>
>>
>>
>> >> $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';
>> ?>
>>
>>
>> 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.
>>
>>
>


--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=gcdmw-win32@m.gmane.org

RE: PHP code query.

am 29.11.2004 23:11:12 von jbonnett

You said the database and table had the same name but it seems the table
is "invcomma" and the database is "jf_invcomma". Also in the PHP you
quote I don't see where you actually executed the SQL statement you
created?

John Bonnett

-----Original Message-----
From: johnf@net2000.com.au [mailto:johnf@net2000.com.au]=20
Sent: Saturday, 27 November 2004 11:24 PM
To: win32@lists.mysql.com
Subject: PHP code query.



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 ;



$dbh=3Dmysql_connect ("localhost", "jf_USER", "password") or die ('I
cannot connect to the database because: ' . mysql_error());
mysql_select_db ("jf_invcomma");
$sql =3D 'SELECT '
. ' `invcomma`.`ISBN`,'
. ' `invcomma`.`TITLE`,'
. ' `invcomma`.`AUTHOR`,'
. ' `invcomma`.`PRICE`,'
. ' `invcomma`.`CAT`'
. ' FROM'
. ' `invcomma`'
. ' WHERE'
. ' `invcomma`.`AUTHOR` =3D "Hall Judy" '
. ' ORDER BY'
. ' `invcomma`.`ISBN`,'
. ' `invcomma`.`TITLE`,'
. ' `invcomma`.`AUTHOR`,'
. ' `invcomma`.`PRICE`,'
. ' `invcomma`.`CAT` LIMIT 0, 30';
?>


Can anyone tell me what I have done wrong and/or the correct code to
make things work please ?

Regards, John.


--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=3Dgcdmw-win32@m.gmane.org

Re: PHP code query.

am 05.12.2004 00:55:46 von johnf

On Sat, 27 Nov 2004 11:43:31 -0800, Janet Valade wrote:
=20
>johnf@net2000.com.au wrote:

< snip >

>> 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=20
>MySQL and selects a database. Then, you save an SQL query in a variable=20
>named $sql. That's all you do. You have no instruction that produce any=20
>output, so you don't get any output.

< snip >

Thanks. A very direct/clear answer. IMO if one doesn't have a clear
grasp of the concepts/steps in using something then they will probably
have problems. As I have had. I thought that when phpMyAdmin said
something like "This is the PHP code" for the query that that is what
it meant. Not that it meant "This is part of the PHP code, you don't
get any output if you use it."

Thank you Janet, and everyone else who contributed input on this
query.

Regards, John.


--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=3Dgcdmw-win32@m.gmane.org