1 message in com.mysql.lists.win32Re: SELECT ... WHERE condition in PHP...
FromSent OnAttachments
Tata Respecia25 Jun 2004 20:00 
Subject:Re: SELECT ... WHERE condition in PHP-MySQL post answered
From:Tata Respecia (tata@yahoo.com)
Date:06/25/2004 08:00:40 PM
List:com.mysql.lists.win32

thank you very much...

both suggestions from everybody

(1) the use single quote, and from lists.mysql.com which is the use of (2) \"%$mkeyword%\""

were correct!

but i think the second needs an explanation so we can apply this in similar
cases...

thanks again..

win@lists.mysql.com wrote:Hello Tata,

Here is the answer to your mail, dated Friday, June 25, 2004, received at
9:15:44 AM:

I see at least TWO errors in PHP code from your post.

------------- FIRST, missing ";" at the end of line - THIS IS WHY PARSE ERROR OCCURS: $mkeyword = $_POST["keyword"]

SHOULD BE: $mkeyword = $_POST["keyword"];

------------- SECOND, and this one is HUGE mistake, in SQL query - you did not include QUOTES for querying in TEXTfield in database:

$my_query = "SELECT stkno,subject,title FROM avtitles where title like $mkeyword ";

SHOULD BE: $my_query = "SELECT stkno,subject,title FROM avtitles where title like \"$mkeyword\"";

------------

the code below is my action.php file which is called by my form page file where the user can enter a string to search for. however it displays an error ("Parse error: parse error, unexpected T_VARIABLE in H:\server\samples\browse_action.php on line 6)

Can anybody help me spot the error in the code?

thank you so much....

code start here:....

You search for :

$mkeyword = $_POST["keyword"]

$host = "localhost"; $user = "meltech"; $password = "hoist"; $db_name = "av"; mysql_connect($host,$user,$password) or die("can not connect"); $my_query = "SELECT stkno,subject,title FROM avtitles where title like $mkeyword
"; $result = mysql_db_query($db_name, $my_query); echo "> style='border-collapse:collapse;'>"; echo "Stock No.SubjectTitle "; while ($content = mysql_fetch_object ($result)) { $stkno = $content -> stkno; $subject = $content -> subject; $title = $content -> title; echo " $stkno > width=150>$subject $title " ; } echo "";

?>>