This question already has an answer here:
- PHP syntax error “unexpected $end” 7 answers
I'm trying to run the following code with the correct connect information and for some reason it isn't working. My php skills are novice and I'm learning via w3schools, but I can't figure out what's wrong and the following message is returned:
Parse error: syntax error, unexpected end of file in /home4/user/public_html/Scripts/demo.php on line 22
As far as I'm concerned everything on the server side is fine. All in all with this code I'm trying to insert info into a database table and then send a user to a different page if it's entered correctly.
<?php
// Create connection
$con=mysqli_connect("host","username","password","db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
// escape variables for security
$name = mysqli_real_escape_string($con, $_POST['name']);
$sql="INSERT INTO testing (Name)
VALUES ('$name')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>