Number of fields - PDO [closed]

1

I've put some crud classes in PDO and almost all of them have 4 or 5 fields in the DB, they worked correctly.

Now I am trying to create a crud of 6 fields, but it does not create the record in the DB at all, I rewrote the class again thinking it to be a typo, but even doing everything again continues the same way, without registering the data in the DB. The isset Post is picking up the form data correctly, naming the variables are 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 is there a different treatment when saving depending on the number of fields?

    
asked by anonymous 21.09.2017 / 18:21

1 answer

2

Seen in the comments, the problem was that your insert sent a null to a field (% with%)% with_%. The cause is in the html form where the input had the attribute $testF . So the solution is to remove this attribute.

Change:

<input type="text" name="testF" class="form-control" value="Disponivel" disabled>

To:

<input type="text" name="testF" class="form-control" value="Disponivel" >
    
21.09.2017 / 19:59