Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP/MySQL problem 1

Status
Not open for further replies.

georgeocrawford

Technical User
Aug 12, 2002
111
GB
Hi,

Please help!

I am using this simple script:

Code:
<html>
<body>
<?php

$db = @mysql_connect(&quot;localhost&quot;, &quot;username&quot;, &quot;password&quot;) or
        die(&quot;could not connect to sql server&quot;);
$dbname = @mysql_select_db(&quot;database&quot;) or
        die(&quot;could not connect to database&quot;);

mysql_select_db(&quot;database&quot;,$db);

$result = mysql_query(&quot;SELECT * FROM repertoire WHERE group = 'baroque' ORDER BY composer ASC&quot;,$db);



if (!$result) echo &quot;MySQL query failed!&quot;;


echo &quot;<table cellpadding=5>\n&quot;;
echo &quot;<tr><td><b>Piece</b></td><td><b>Composer</b></td><td><b>Group</b></td></tr>\n&quot;;
while ($myrow = mysql_fetch_array($result) ) {
	printf(&quot;<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n&quot;, $myrow[&quot;piece&quot;], $myrow[&quot;composer&quot;], $myrow[&quot;group&quot;]);
}
echo &quot;</table>\n&quot;;


mysql_close ($db);


?>
</body>
</html>

At present, this outputs:

Code:
MySQL query failed!


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sapphire/public_html/test.php on line 22

I have determined that the problem is with &quot;WHERE group = 'baroque' &quot; - because it works fine when I leave it out. I don't understand - I think this is the correct syntax, but maybe I'm wrong???

Please help!
 
I'm getting closer!

when I replace:

Code:
$query = &quot;SELECT * FROM repertoire WHERE group = 'baroque' ORDER BY composer ASC&quot;;

with

Code:
$query = &quot;SELECT * FROM repertoire WHERE `group` = 'baroque' ORDER BY composer ASC&quot;;

...it works.

It's all to do with the ` character either side of &quot;groups&quot;. This seems to be a grave accent (`), and is thus different from a single quote (').

In a php script I have which someone else wrote, a subroutine is run which detects the MySQL version, and then uses the grave accent when the version is newer than 3.23.06 .

ie:
Code:
if ($mysql_server_version > 32306){
		$quote = &quot;`&quot;;
	}

$quote is then used to enclose a number of words in the MySQL enquiries.

Can anyone explain all this to me? Why, and when, is this character used? Is it a grave accent, or something else? Why did it change for version 3.23.06?

Thanks for any help!

George
 
i think this prob is caused when using 'group' as the name of the column - group is an sql command so mysql needs to determine what is command and what is name of table/column/database
 
piti,

georgecrawford forgot to vote you a star. So I did. ______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top