-1

I am trying to insert different jobs into a database and i want to check if there already is an entry for that job in the table. The idea was to use an SQL Statement that returns either true or false depending on the job existing in the table or not.

The connection is propperly established and i can get the values from a column using a SELECT statement as an array by using a similar syntax.

$sql = "SELECT COUNT(*) FROM job WHERE key = Pilot";

$result= $db->executeQuery($sql);

if($result == true) {
    // action 1
}
else{
    // action 2
}

the result from the executeQuery($sql) is a boolean but it always returns false, whether the job already exists or not but i was hoping to get true when the job exists.

AlCapony
  • 1
  • 4

1 Answers1

0

Your SQL is invalid, key is a reserved word and should be quoted with backticks. Also the parameter you have should be quoted as well:

$sql = "SELECT COUNT(*) FROM job WHERE `key` = 'Pilot'";
JensV
  • 3,997
  • 2
  • 19
  • 43