2
I made some changes to the script and is generating two errors:
- Warning: Pdostatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid Parameter number: number of bound variables does not match number of tokens in /localhost/admin/crud/edit.php on line 33
- Warning: Cannot Modify header information - headers already sent by (output Started at localhost/admin/crud/edit.php:33) in localhost/admin/crud/edit.php on line 36
What was done: I just added a select to save the data to the database. The script:
if(!empty($_GET['codusuario']) && $_SERVER['REQUEST_METHOD'] == 'GET'){
$stm = $pdo->prepare('SELECT * FROM usuario WHERE codusuario = ?');
$stm->bindParam(1, $_GET['codusuario'], PDO::PARAM_INT);
$stm->execute() or die(implode('', $pdo->errorInfo()));
$_POST = $stm->fetch(PDO::FETCH_ASSOC);
}
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if(empty($_POST['codusuario'])){
$sql = 'INSERT INTO usuario (email,senha,chave,select2,pergunta) VALUES (?, ?, ?, ?, ?)'; //email, senha, chave, pergunta
$stm = $pdo->prepare($sql);
$stm->bindParam(1, $_POST['email']);
$stm->bindParam(2, $_POST['senha']);
$stm->bindParam(3, $_POST['chave']);
$stm->bindParam(4, $_POST['select2']); //@new select box
$stm->bindParam(5, $_POST['pergunta']);
$stm->execute();
} else {
$sql = 'UPDATE usuario SET email = ?, senha = ?, chave = ?, pergunta = ? WHERE codusuario = ?';
$stm = $pdo->prepare($sql);
$stm->bindParam(1, $_POST['email']);
$stm->bindParam(2, $_POST['senha']);
$stm->bindParam(3, $_POST['chave']);
$stm->bindParam(4, $_POST['pergunta']);
$stm->bindParam(5, $_POST['codusuario'], PDO::PARAM_INT); //old number is 5
$stm->bindParam(6, $_POST['select2']);
$stm->execute();
}
header('Location: index.php');
exit;
}
Line 33 is the fourth of the part you posted here?
– bfavaretto
@bfavaretto this code is working together with html
– the flash