0
<?php
$x=$_POST[ 'firstname'];
$y=$_POST[ 'lastname'];
$servername = "localhost"
$username = "root";
$password = "";
$dbname="dbl";

i keep getting the error Parse error: syntax error, unexpected '$username' (T_VARIABLE) in C:\xampp\htdocs\test\submit.php on line 24 can anyone help

Complete code:

<head>
<style>
table {
    font-family: Arial, sans-serif;
    border-collapse: collapse;
    width: 100%;
}

td, th {
    Border: lpc solid #dddddd
    text-align: left;
    padding: 8px
}

tr:nth-child(even) {
    background-color: #dddddd
}
</style>
</head>
<?php
$x=$_POST[ 'firstname'];
$y=$_POST[ 'lastname'];
$servername = "localhost"
$username = "root";
$password = "";
$dbname="dbl";
// Create connection
$conn = new mysqli($servername, $username, $password,$dbname);

// Check connection
if ($conn-> connection_error) {
    die("connection failed: " . $conn->connection_error);
}
echo "connected successfully";
$sql = "INSERT INTO 'user' ('fname', 'lname') VALUES ('$x' , Sy')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "error: " .  $sql . "<br>" . $conn->error;
}
$sql = "select id, fname, lname FROM user";
$result =
$conn->close () ;
?>
Sean
  • 1
  • 1
  • 2
    Fix this `typo` $servername = "localhost" `;` missing semicolon – A l w a y s S u n n y Sep 20 '17 at 16:27
  • A missing semicolon is almost always the cause of an unexpected variable parse error. The error message tells you the line number, so just check the previous line. – Don't Panic Sep 20 '17 at 16:30
  • thank you Don't Panic and Being Sunny – Sean Sep 21 '17 at 16:06
  • ok i fixed that error but now Uncaught Error: Class 'MySQL' not found in C:\xampp\htdocs\test\submit.php:26 Stack trace: #0 {main} thrown in C:\xampp\htdocs\test\submit.php on line 26 – Sean Sep 21 '17 at 16:10

0 Answers0