error displaying the data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
voonmin
Forum Newbie
Posts: 1
Joined: Tue Feb 28, 2006 9:47 pm

error displaying the data

Post 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]
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

remember to quote all named array indices. e.g.:

Code: Select all

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