insert only one field with Pdo

Asked

Viewed 81 times

0

Eae you guys, my problem is the following am using php’s PDO object to insert records into the database, the problem is when I try to insert only one field into a table example:

$query = 'INSERT INTO alunos (nome) VALUES(:nome)'; $stmt= $conexao->prepare($query); $stmt->bindValue(':nome',$_POST['nome']); $stmt->execute();

well if I try to insert only one field do not however if I specify all there works example:

$query = 'INSERT INTO alunos (numero,nome,username,senha) VALUES(:numero,:nome,:username,:senha)'; $stmt= $conexao->prepare($query); $stmt->bindValue(':numero',$_POST['numero']); $stmt->bindValue(':nome',$_POST['nome']); $stmt->bindValue(':username',$_POST['username']); $stmt->bindValue(':senha',$_POST['senha']); $stmt->execute();

is that I’m doing something wrong in the first example?

1 answer

0


missing a parentheses at the end guy, Edit: vc need to close sql statement and ferchar prepare parentheses

and try to do so:

$variavel = filter_var($_POST['nome']);
$stmt = $conexao->prepare("INSERT INTO alunos (nome) VALUES(:nome)");
$stmt->bindParam(':nome', $variavel);
$stmt->execute();
  • yes I ended up typing wrong here in stack however when I use I do right and still not from $query = "INSERT INTO students (name) VALUES (:name)"; $stmt = $connected->connect()->prepare($query); $stmt->bindValue(':name',$name); $stmt->execute();

  • tried to use bindParam as in the example above?

  • try to put $connection->beginTransaction(); before $stmt->execute();

  • I tried using the above examples but it doesn’t work

  • check your table if by chance the fields you do not want to enter are marked as null except id, otherwise it will not work

  • Vlw guy really was that, thank you so much

  • for nothing, mark the answer as accepted.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.