0

I am trying to see if there is a record in the wumpuses database with a given $row and $columm.

    $row = filter_input(INPUT_GET, "row", FILTER_SANITIZE_SPECIAL_CHARS);;
    $column = filter_input(INPUT_GET, "column", FILTER_SANITIZE_SPECIAL_CHARS);

    $command= "SELECT `row`, column FROM wumpuses WHERE `row` = ? AND column = ? ";
    $stmt= $dbh->prepare($command);
    $params= ["$row", "$column"];
    $success= $stmt->execute($params);

   if ($success)
     {

        echo "yes";
    }
    else {

        echo "no";
    }

I am getting an error on the last line of code: $success= $stmt->execute($params); Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'column FROM wumpuses WHERE row = '4' AND column = '4'' at line 1.

I am new to SQL and not sure what is the proper syntax to check for existing records in a database and if they are there then print a success message.

dlohammer
  • 1
  • 1
  • `column` is a reserved word in MySQL, so you will need to use backticks round each time you use it in a statement. – Nigel Ren Nov 01 '21 at 06:24

0 Answers0