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?
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();
– Danilo Henriq
tried to use bindParam as in the example above?
– Senpai
try to put $connection->beginTransaction(); before $stmt->execute();
– Senpai
I tried using the above examples but it doesn’t work
– Danilo Henriq
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
– Senpai
Vlw guy really was that, thank you so much
– Danilo Henriq
for nothing, mark the answer as accepted.
– Senpai