Page 1 of 1

error displaying the data

Posted: Tue Feb 28, 2006 10:14 pm
by voonmin
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


hi!!
i hv trouble in retrieve the data from mysql ....  i not able to display the search result....it shows parse error, unexpected T_IF....can anyone help me check out for this??  ur help is highly appreciated!!  


this is the search page with a search column:

Code: Select all

<card id="card2" title="SearchPage">
Search by word/phrase:
<form method="post" action="mine.wml#card1" >
<input type="text" name="phrase" size="12"/><br/>
<img src="search2.jpg"/><br/>
<input type="submit" value="Search" />
</form><br/>
</card>
and here's the page to display the result:

Code: Select all

<card id="card1" title="Result">
<? php


if ($_POST[phrase]=="")
{ 
echo "Please search again u have not key in word/phrase";
}

else 
{
$db_name="translation";
$table_name="english_malay";
$connection=@mysql_connect("localhost","root","") or die(mysql_error());
$db=@mysql_select_db($db_name,$connection) or die(mysql_eror());
$sql="select * from $table_name where english='%".$_POST[phrase]."%'";
$result=@mysql_query($sql,$connection) or die(mysql_error()); 
$num_results=mysql_num_rows($result);
echo '<p>the results are:'.$num_results.'</p>';

for($i=0;$i<$num_results;i++)
{
$row=mysql_fetch_array($result);
echo '<p><strong>'.($i+1).;
$a=stripslashes($row['english']);
$b=stripslashes($row['malay']);
echo $a=$b;
}
}
?>
</card>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Tue Feb 28, 2006 10:47 pm
by nickman013
Try this

Code: Select all

<?php 
if($_POST[phrase]=="") 
{ 
echo "Please search again u have not key in word/phrase"; 
} 

else 
{ 
$db_name="translation"; 
$table_name="english_malay"; 
$connection=@mysql_connect("localhost","root","") or die(mysql_error()); 
$db=@mysql_select_db($db_name,$connection) or die(mysql_eror()); 
$sql="select * from $table_name where english='%".$_POST[phrase]."%'"; 
$result=@mysql_query($sql,$connection) or die(mysql_error()); 
$num_results=mysql_num_rows($result); 
echo '<p>the results are:'.$num_results.'</p>'; 

for($i=0;$i<$num_results;i++) 
{ 
$row=mysql_fetch_array($result); 
echo '<p><strong>'.($i+1).; 
$a=stripslashes($row['english']); 
$b=stripslashes($row['malay']); 
echo $a=$b; 
} 
} 
?>
Also use PHP tags when posting PHP on the forum.

Posted: Tue Feb 28, 2006 11:02 pm
by feyd
remember to quote all named array indices. e.g.:

Code: Select all

$_POST[name]
// vs
$_POST['name']
(the latter is proper)