Using the code below, the sql insert is inserting
':firstName', ':lastName', and ':address' when I'm wanting "john", "doe" and "555 test avenue"
Thoughts? I don't see where I'm making a mistake....
':firstName', ':lastName', and ':address' when I'm wanting "john", "doe" and "555 test avenue"
Thoughts? I don't see where I'm making a mistake....
Code:
<?php
$firstName = "John";
$lastName = "Doe";
$address = "555 test avenue";
try {
$conn = new PDO("mysql:host=localhost;dbname=myDB", 'myUser', 'pass123!');
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// prepare sql and bind parameters
$stmt = $conn->prepare("
INSERT INTO tbl_jobApplications (firstName, lastName, address)
VALUES (NULLIF(':firstName', ''), NULLIF(':lastName', ''), ':address')
");
$stmt->bindParam(':firstName', $firstName);
$stmt->bindParam(':lastNname', $lastName);
$stmt->bindParam(':address', $address);
$stmt->execute();
echo "New records created successfully";
}
catch(PDOException $e)
{
echo "Error: " . $e->getMessage();
}
$conn = null;
?>
Last edited: