-3

I have a MySQL DB from where i next to extract data based on user search.

I have no problem displaying the post variable like this :

<?php 

if (isset($_POST)) {
$name = htmlspecialchars($_POST['name']);      
echo "Results  - " . $name ."\n";
}

$servername = "localhost"; 
$username = "root";
$password = "root";
$dbname = "test";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);

$conn->close();
?>

The error -

Parse error: syntax error, unexpected end of file.

As soon as I add a MySQL connection, without even any query to be done, I get a parse error. Why is that ?

I have tried adding a specific query as I need the results displayed.

I have also tried using a different from of submitting, still no luck, getting same parse error.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Vitalik Jimbei
  • 141
  • 1
  • 9

1 Answers1

0

I think you have a syntax error.

if ($conn->connect_error) { 
    die("Connection failed: " . $conn->connect_error); 

} <--- u have missed this

$conn->close();

Final code

<?php 

if (isset($_POST)) {
$name = htmlspecialchars($_POST['name']);      
echo "Results  - " . $name ."\n";
}

$servername = "localhost"; 
$username = "root";
$password = "root";
$dbname = "test";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);

}    <-------    this is missing in your code.

$conn->close();

?>
Niranjan N Raju
  • 12,047
  • 4
  • 22
  • 41