1
I built some crud classes in PDO and almost all have 4 or 5 fields in DB, worked correctly.
Now I’m trying to create a crud of 6 fields, but does not create the record in DB at all, I rewrote the class thinking it is some typo, but even doing everything again remains the same, without registering the data in DB. isset Post is taking the form data correctly, variable naming is correct
With 4 columns in DB:
public function create($testA,$testB,$testC,$testD)
{
try
{
$stmt = $this->db->prepare("INSERT INTO ColunaUm(testA,testB,testC,testD) VALUES(:testA, :testB, :testC, :testD)");
$stmt->bindparam(":testA",$testA);
$stmt->bindparam(":testB",$testB);
$stmt->bindparam(":testC",$testC);
$stmt->bindparam(":testD",$testD);
$stmt->execute();
return true;
}
catch(PDOException $e)
{
echo $e->getMessage();
return false;
}
}
With 6 Columns:
public function create($testA,$testB,$testC,$testD,$testE,$testF)
{
try
{
$stmt = $this->db->prepare("INSERT INTO ColunaDois(testA,testB,testC,testD,testE,testF) VALUES(:testA, :testB, :testC, :testD, :testE, :testF)");
$stmt->bindparam(":testA",$testA);
$stmt->bindparam(":testB",$testB);
$stmt->bindparam(":testC",$testC);
$stmt->bindparam(":testD",$testD);
$stmt->bindparam(":testE",$testE);
$stmt->bindparam(":testF",$testF);
$stmt->execute();
return true;
}
catch(PDOException $e)
{
echo $e->getMessage();
return false;
}
}
In PDO there is a different treatment when saving depending on the amount of fields?
If no error is returned. Try using toString() to see what SQL is returning.
– cHida
add the structure of the Colunadois table
– Felipe Duarte
@Felipeduarte the table Colunadois this ok tbm, I checked the data types, the names and are identical
– Gislef
@cHida you have an example of how to use the
toString()
? would be:public function __toString() { return $this->Db; }
?– Gislef
What is the error message?
– rray
@rray without error message
– Gislef
Do the following and see if any error appears, change:
$stmt->execute();
forif(!$stmt->execute()){ print_r($stmt->errorInfo());}
. The code of the question seems correct I imagine that this is not the real code (the one with problem).– rray
@rray returns error that was not registered in DB because of the isset I put, if not register appears the message was not registered. But PHP error alert is not showing up even with the code you indicated
– Gislef
Has no
isset()
in the question code. It becomes complicated to answer on top of a code other than real.– rray
ok I took isset from custom error: this is returning the following error:
SQLSTATE[23000]: Integrity constraint violation: 1048 Le champ 'testF' ne peut �tre vide (null)
– Gislef
testF is type Enum, in the form I am passing the value like this:
<input type="text" name="testF" class="form-control" value="Disponivel" disabled>
– Gislef
Apparently came empty or the value does not exist no source table. Okay this error message in French?
– rray
It is better to edit the question and add these details. pq does not create a new table or treat this logic in PHP than to use an Enum?
– rray
It is at least curious, the other tests with less fields also worked with Enum in the same way, and did not have this error
– Gislef
error is also appearing:
Notice: Undefined index: testF
– Gislef
Must not send its value pq the field is as
disabled
– rray
our kkk was just that, just the disabled thing I didn’t even notice it, thinking it was something in the PHP code. Thanks solved
– Gislef