Correct Syntax?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
eggoz
Forum Commoner
Posts: 43
Joined: Fri Dec 27, 2002 8:51 pm

Correct Syntax?

Post by eggoz »

I have this query that calls all fields from a table called testtable, where column two should equal $value. $value is a value that I passed from the previous page. This is what I have right now:

Code: Select all

$record = mysql_query ( SELECT * FROM testtable.* WHERE two = $value );
Where am I going wrong?
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post by Rob the R »

You are missing some double-quotes and have an extraneous asterisk. Try this:

Code: Select all

<?php
$result = mysql_query ("SELECT * FROM testtable WHERE two = '$value' " );
?>
I put single-quotes around the $value in the query; this is assuming that the column TWO in your table is character. If it is numeric, the single-quotes around $value are not needed.

Also note that you'll have to use mysql_fetch_array() to get at the records (rows) this query returns. mysql_query() just returns a resource and not the actual record set of the query.
Post Reply