Note that there are some explanatory texts on larger screens.

plurals
  1. POUncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found
    text
    copied!<p>I tried to run the following code but it returned this erros:<br> Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column ''1'' in 'field list'' in /home/cardg/cards/jogar.php:59 Stack trace: #0 /home/cardg/cards/jogar.php(59): PDOStatement->execute() #1 {main} thrown in /home/cardg/cards/jogar.php on line 59<br> Why this is happening?<br></p> <pre><code>&lt;?php include('config.php'); $usuarion = $_SESSION['login']; $senhan = $_SESSION['senha']; // $attrs is optional, this demonstrates using persistent connections, // the equivalent of mysql_pconnect $attrs = array(PDO::ATTR_PERSISTENT =&gt; true); // connect to PDO $pdo = new PDO('mysql:host='.$dbservidor.';dbname='.$dbnome.'', $dbusuario, $dbsenha); // the following tells PDO we want it to throw Exceptions for every error. // this is far more useful than the default mode of throwing php errors $pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // prepare the statement. the place holders allow PDO to handle substituting // the values, which also prevents SQL injection $stmt = $pdo-&gt;prepare("SELECT estado,usuario1,usuario2,usunivel,id FROM duelos WHERE estado=:estadox AND usuario1!=:usuario"); // bind the parameters $stmt-&gt;bindValue(":estadox", 0); $stmt-&gt;bindValue(":usuario", $usuarion); // initialise an array for the results $duelos = array(); if ($stmt-&gt;execute()) { while ($row = $stmt-&gt;fetch(PDO::FETCH_ASSOC)) { $products[] = $row; echo $row['usuario1']; } } $usuario = $pdo-&gt;query("SELECT id,apelido,usuario,nivel FROM usuarios WHERE usuario = '".$usuarion."' AND senha ='".$senhan."'"); $usulinha = $usuario-&gt;fetch(PDO::FETCH_ASSOC); $usuarioid = $usulinha['id']; $usunivel - $usulinha['nivel']; $sqlduelos = "SELECT COUNT(*) FROM duelos WHERE (estado = 1 AND usuario2 = 0)"; if ($resl = $pdo-&gt;query($sqlduelos)) { /* Check the number of rows that match the SELECT statement */ if ($resl-&gt;fetchColumn() &gt; 0) { $msg = "True msg"; } else{ $msg = "false msg"; $inid = $pdo-&gt;prepare("INSERT INTO `duelos` (`usuario1`, `usunivel`) VALUES ( `:usua`, `:usuni`)"); $inid-&gt;bindParam(':usua', $usuarioid); $inid-&gt;bindParam(':usuni', $usunivel); $inid-&gt;execute(); } } // set PDO to null in order to close the connection $pdo = null; ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload