Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private function updateSet(){
- $set='';
- for($x=0;$x < $this->numFields();$x++){
- $field = $this->fieldName($x);
- $value = isset($_POST[$field]) ? $_POST[$field] : '';
- // A linha abaixo gerará a linha: $nome = 'Nome do cliente';
- //$$field = $_POST[$field];
- $$field = $value;
- // Este if gerará a variável $set contendo "$nome = :$nome, $email = :$email, ...";
- if($x < $this->numFields()-1){
- $set .= "$field = :$field,";
- }else{
- $set .= "$field = :$field";
- }
- }
- return $set;
- }
- public function update($id){
- if(isset($_POST['send'])){
- $sql = "UPDATE {$this->table} SET {$this->updateSet()} WHERE id = :id";
- $sth = $this->pdo->prepare($sql);
- for($x=0;$x < $this->numFields()-1;$x++){
- // Se inserir um
- // print $field.'-'; ele me mostra os 6 campos, então por que invalid parameter number?
- $field = $this->fieldName($x);
- $sth->bindParam(":$field", $_POST["$field"], PDO::PARAM_INT);
- }
- if($sth->execute()){
- print "<script>location='index.php?table=$this->table';</script>";
- }else{
- print "Error on update register!<br><br>";
- }
- }
- }
- Ao tentar editar um registro recebo o erro:
- Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number in /backup/www/auto-crud2/pt_BR/classes/crud.php on line 246
- Linha 246 é esta:
- if($sth->execute()){
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement