i have this code that i have worked on and it is throwing an exception, but i cannot troubleshoot the cause.
$servername = "localhost";
$username = "root";
$password = "Jimranoot";
$first = $_POST["firstiename"];
$last = $_POST["lastiename"];
$sql = "INSERT INTO RegisteredUsers (firstname, lastname)
VALUES ($first, $last)";
$conn = new PDO("mysql:host=$servername;dbname=jimmyneutron", $username, $password);
try {
if (!empty($first) && !empty($last)) {
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->exec($sql);
echo "Recorded Successfully!";
} else {
echo "Field Must Not Be Empty!";
}
} catch (PDOException $e) {
print "WRONG";
}
When i run this code by supplying inputs from HTML, it simply returns "WRONG". Thank you in advance for your help!