0

I managed to create a search bar that searches my forum,it searches the categories table then displays the results,however i want to make a link that redirects me to that result found ,for example i search for a category called business and it displays the result but i want the result to have a link such that when i click it it redirects me to that category but i am getting an error

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:\xampp\htdocs\mysite\captcha2\tut.php on line 43 

my code on line 43 is

<td>'.$category_title.="<a href='view_category.php?cid=".$id."' class='cat_links'>".$title." - <font size='-1'>".$description."</font></a>"'</td> </tr>' 

and this is my search bar code

if(isset($_POST['search'])){ //form submitted, clicked Submit Search $query = strip_tags(mysql_real_escape_string($_POST['query'])); //try to prevent sql injections if(!$query){ //not enterered a query echo 'You must enter a search query!'; }else{ $table = 'categories'; //the table you want to search $row = 'category_title'; //the row in which you want to search $sql = mysql_query("SELECT * FROM `".$table."` WHERE `".$row."` LIKE '%".$query."%'"); //search query if($sql){ //no errors if(mysql_num_rows($sql) == 0){ //No results found. echo 'No results were found for <strong>'.$query.'</strong>'; }else{ //one or more results have been found echo 'We have found <strong>'.mysql_num_rows($sql).'</strong> for <strong>'.$query.'</strong>.<br><br> <table> <tbody> <tr> <td><strong>category_title</strong></td> </tr>'; while($r = mysql_fetch_array($sql)){ //get data of every user where their category_title is like the $query string $category_title = $r["category_title"]; //lets put the part they searched in bold. $category_title = str_ireplace($query, '<strong>'.$query.'</strong>', $category_title); //lets put the part they searched in bold. echo '<tr> <td>'.$category_title.="<a href='view_category.php?cid=".$id."' class='cat_links'>".$title." - <font size='-1'>".$description."</font></a>"'</td> </tr>'; } echo '</tbody></table>'; } }else{ echo 'Sorry, an MySQL error occurred:<br><br>'.mysql_error(); //an error occurred, so echo it } } }else{ //not clicked Submit Search, so echo the form echo '<h3>Search</h3> <br><br> <form method="post"> <label for="q"></label> <input type="text" size="100" name="query" id="q" value="m0nsta."> <input type="submit" name="search" value="Search"> </form>'; } ?> 
1
  • 2
    Get an editor with at least the most basic minimal just-enough-to-use syntax highlighting. Commented Dec 28, 2012 at 6:30

3 Answers 3

3

Get rid of the = sign, and an extra quotation

<td>'.$category_title.="<a href='view_category.php?cid=".$id."' class='cat_links'>".$title." - <font size='-1'>".$description."</font></a>"'</td> </tr>' 

Should be

<td>'.$category_title."<a href='view_category.php?cid=".$id."' class='cat_links'>".$title." - <font size='-1'>".$description."</font></a></td> </tr>" 
Sign up to request clarification or add additional context in comments.

1 Comment

Hi Bryan i think ending part of your suggestion has a small typing mistake? the last string starts with a double quote and ends on a single one
1
."</font></a>"'</td> </tr>'; 

This should end with a double quotation mark and not single like

echo '<tr> <td>'.$category_title."<a href='view_category.php?cid=".$id."' class='cat_links'>".$title." - <font size='-1'>".$description."</font></a></td></tr>"; 

3 Comments

Notice: Undefined variable: id in C:\xampp\htdocs\mysite\forum part two\index.php on line 75 Notice: Undefined variable: title in C:\xampp\htdocs\mysite\forum part two\index.php on line 75 Notice: Undefined variable: description in C:\xampp\htdocs\mysite\forum part two\index.php on line 75 thats im getting if i use your code
That means those variables that you are using there are not defined before, but it also means that the syntax error is resolved
As far as i can see in your code those 3 variables that you have used in this statement are not defined. $title,$id,$description
0

USE

 <td>'.$category_title."=<a href='view_category.php?cid=".$id."' class='cat_links'>".$title." - <font size='-1'>".$description."</font></a></td> </tr>'"; 

Make use of eclipse IDE as a habit, it will really help you to avoid such errors

1 Comment

or Netbeans or anything else, but an IDE. Your answer is not that well anyway (remove =).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.