Syntax Error? REPOST with proper PHP tags this time.

Hello,

I am new to the forum and PHP. I am having a little trouble with the syntax of my Select statement. Here is what I have:

[php]
$var = $_POST[“lname”];
$trimmed = trim($var);

$query = “Select
Account_Info.Account_Num,
Account_Info.Owner_Name1,
Account_Info.Owner_Address_Line2,
account_apprl_year.TOT_Val
From Account_Info
INNER JOIN account_apprl_year
ON Account_Info.Account_Num=account_apprl_year.Account_Num
Where Owner_Name1 like “%$trimmed%””

[/php]

I’m simply trying to search a MySQL database by last name and retrieve the records. I’m catching the last name in the POST and trimming it. Now I would like to use the trimmed variable in my Select statement but it is not working. I can’t see where the problem is. Does my Select statement look like it is formatted properly?

Thanks,
Darin

The problem is right here:
$query = "Select
You forgot to call a mysql_query, like
$query = mysql_query(“Select
and at the end:
like “%$trimmed%””);
Otherwise it is treated like a string, not an action. If you like, you could do:

$query = “Select
Account_Info.Account_Num,
Account_Info.Owner_Name1,
Account_Info.Owner_Address_Line2,
account_apprl_year.TOT_Val
From Account_Info
INNER JOIN account_apprl_year
ON Account_Info.Account_Num=account_apprl_year.Account_Num
Where Owner_Name1 like “%$trimmed%””

$themysqlaction = mysql_query($query);

I’m pretty sure that works
Also, select, from, where, and like are all supposed to be completely uppercase.
SELECT
FROM
WHERE
LIKE
as far as I know.

Sponsor our Newsletter | Privacy Policy | Terms of Service