Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause''

Mas Enggar picture Mas Enggar · Feb 11, 2015 · Viewed 12.1k times · Source
<?php 
require 'database.php';
$id = 0;

if ( !empty($_GET['user_id'])) {
    $id = $_REQUEST['user_id'];
}

if ( !empty($_POST)) {
    // keep track post values
    $id = $_POST['user_id'];

    // delete data
    $pdo = Database::connect();
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "DELETE FROM admin  WHERE id = ?";  ===> Wrong on here.. //LINE18
    $q = $pdo->prepare($sql);
    $q->execute(array($id));
    Database::disconnect();
    header("Location: index.php"); 

} 

?>

somebody can help me? why i got Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]

sorry my english is bad, thanks

Answer

stwalkerster picture stwalkerster · Feb 11, 2015

The error message indicates that the table admin in your database does not have a column called id. You need to check what columns are available in the table, but without more information (such as the table definition), I can't be more help.