-1

Parse error: syntax error, unexpected '$ind' (T_VARIABLE) in C:\xampp server\htdocs\Sahith\sy.php on line 13.

This error is shown when I run

    <?php   
    $dbhost = 'localhost:3306';
    $dbuser = 'root';   
    $dbpass = '';   
    $se = ['index'];  

    $conn = mysql_connect($dbhost, $dbuser, $dbpass);  

    if(! $conn ) {    
      die('Could not connect: ' . mysql_error());  
     }    

    $sql = 'SELECT * FROM `student` WHERE `Index No.` = '$se'';
    mysql_select_db('school'); 
    $retval = mysql_query( $sql, $conn );   
   if(! $retval ) {     
      die('Could not get data: ' . mysql_error());  
     }    

   while($row = mysql_fetch_assoc($retval)) {  
   echo "Index  :{$row['Index No.']}  <br> ".   
    "NAME : {$row['Name']} <br> ".            "--------------------------------<br>";    }    
   echo "Fetched data successfully\n";   
   mysql_close($conn); ?>

this code

How to solve this???

1 Answers1

0

You have a syntax error here :

$sql = 'SELECT * FROM `student` WHERE `Index No.` = '$se'';

change to

$sql = 'SELECT * FROM `student` WHERE `Index No.` = "'.$se.'"';

Please have a look to : PHP Parse/Syntax Errors; and How to solve them?

And,

WARNING: Your code is vulnerable to SQL injections and may compromise the security of your database and server. You should use PDO or mysqli APIs to secure your SQL queries, and using prepare function.

Syscall
  • 19,327
  • 10
  • 37
  • 52