-1

I want to navigate to a section of a php page which is dynamically assigned a section as..

     mysql_connect("localhost", "root", "") or die(mysql_error()); 
     mysql_select_db("somedb") or die(mysql_error()); 
     $data = mysql_query("SELECT * FROM events") 
      or die(mysql_error()); 
     while($info = mysql_fetch_array( $data )) 
     { 
     Print "<hr>";  
     Print "<section id=".$info['title'] .">"; 
     Print "<h1>".$info['title'] . "</h1>"; 
     echo nl2br ( $info['desc'],true ) ;
     Print "</section>";} 
     ?> 

from this php code

    <?php 
    mysql_connect("localhost", "root", "") or die(mysql_error()); 
    mysql_select_db("somedb") or die(mysql_error()); 
    $data = mysql_query("SELECT title FROM events") 
    or die(mysql_error()); 
    while($info = mysql_fetch_array( $data )) 
    { 
    echo "<a href="events.php#.$info['title'].">"
    Print " ".$info['title'] .""; 
     }
     ?> 

I get an error like

   Parse error: syntax error, unexpected 'events' (T_STRING) in C:\xampp\htdocs\IETE\index -    Copy.php on line 91

Kindly help :)

Yashesh
  • 39
  • 1
  • 7

1 Answers1

0

The error message and the StackOverflow syntax highlighter are clearly showing the problem. Quotes enclose a string but you have a quote in your string, which needs escaping, or you can use single quotes to surround the string instead, which is arguably easier to read than escaping the double quotes.

This line is the issue:

echo "<a href="events.php#.$info['title'].">"

As you can see from the syntax highlighting, the quote before 'events' breaks you out of the string. Everything following the hash is interpreted as a comment.

Change it to use single quotes:

echo '<a href="events.php#' . $info['title'] . '">';

or alternatively, escape the quotes within the string:

echo "<a href=\"events.php#" . $info['title'] . "\">";

As an aside, if you're using a plain text editor I strongly recommend switching to an IDE with more advanced features for the languages being used.

Community
  • 1
  • 1
bcmcfc
  • 23,143
  • 28
  • 104
  • 170