issue with $_POST and mysql query

Wednesday, November 4, 2015

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.



Can you help ?

0 comments:

Post a Comment