I'm not much of a php coder, but I'm trying to learn by building a basic webapp.
In the code below, I'm getting an error of
Call to a member function query() on a non-object in /getApplications.php on line 24
line 24 // if ($conn->query($sql) === TRUE) {
I'm trying to create a function called createApplication which takes a set of arguments and inserts it into a database table. I think my overall function syntax is correct but how I'm calling the query is wrong. Also, I removed all but 4 of the arguments for sake of making code more legible.
Thoughts?
In the code below, I'm getting an error of
Call to a member function query() on a non-object in /getApplications.php on line 24
line 24 // if ($conn->query($sql) === TRUE) {
Code:
function createApplication($firstName, $lastName, $address, $city)
{
$conn = mysql_connect('localhost', 'user', 'passme123!', 'jobApplications');
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else {
$sql = "INSERT INTO tbl_jobApplications (firstName, lastName, address, city)
VALUES ('$firstName', '$lastName', '$address', '$city')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
}
else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
mysql_close($conn);
}
I'm trying to create a function called createApplication which takes a set of arguments and inserts it into a database table. I think my overall function syntax is correct but how I'm calling the query is wrong. Also, I removed all but 4 of the arguments for sake of making code more legible.
Thoughts?
Last edited: