column count doesn't match the value count at row 1_database insert error

89
February 11, 2019, at 08:30 AM

Been working on this for a while. For some reason even though I have enough values and columns, I get "column count doesn't match value count at row 1" error.

I tried passing $values as array-- doesn't work because its array. Tried putting $values and $kk inside '', but didn't work. This version of code yielded least amount of errors.

<?php

    $dbh = new mysqli("localhost", "admin", "password", "database");
    $dta= mysqli_query($dbh,"SELECT * FROM agents");
    include_once("class.php");
    $agntProperties = new agntObjects;
    $ary = array ($agntProperties->agntID=$_GET['id'] => array(
    $agntProperties->agntFName=$_GET['fname'],//error occurs"unknown column in field list
    $agntProperties->agntMiddleInitial=$_GET['mname'],
    $agntProperties->agntLastname = $_GET['lname'],
    $agntProperties->agntBusPhone = $_GET['agntbusphone'],
    $agntProperties->agntEmail = $_GET['email'],
    $agntProperties->agntPosition = $_GET['agntpos'],
    $agntProperties->agencyId = $_GET['agencyId']));
    $arryy = array ((int)$_GET['id'],$_GET['fname'],$_GET['mname'],$_GET['lname'],
    $_GET['agntbusphone'],$_GET['email'],$_GET['agntpos'],(int)$_GET['agencyId']);



function insertDta(array $agntArray, $database, $table)
{
    $agntProperties = $GLOBALS['agntProperties'];
    $database=$GLOBALS['dbh'];//it should be something that changes depending on agent

    $agntdata= get_class($agntProperties)::$fields; // $fields properties are below for reference
    //public static $fields = array ('AgentId','AgtFirstName', 'AgtMiddleInitial', 'AgtLastName','AgtBusPhone','AgtEmail', 'AgtPosition','AgencytId')
    $agntprops= implode(',', $agntdata);
    $vals= array();
    foreach($agntArray as $k=>$v)
    {
        $kk=$k;
        $vals= $v;        
    }
    $values= implode(',',$vals);

    $sql = "INSERT INTO agents ($agntprops) VALUES ($kk,'$values')";

    $result= mysqli_query($database,$sql);
    if($result)
    {
        echo "all good";
    }else {
        echo "update failed"."<br>";
        echo  mysqli_error($database);
    }

}

    insertDta($ary,"", "");
    $dbh-> close();

?>

Expected results would be: being able to insert all the values such as agentid, firstname, etc to database.

READ ALSO
cannot get id from ajax

cannot get id from ajax

I can't get the id from the js file, I don't know if the js code or the php code is wrongCan someone help? problem seems to be from index

20
Inserting 2 rows instead of one: angular and php

Inserting 2 rows instead of one: angular and php

I am working with angular 6 and phpWhen i add an entity whith my application, i find that the backend is inserting 2 rows in the table instead of one

43
Merge dataframes by left join SQL &amp; Pandas

Merge dataframes by left join SQL & Pandas

I made two tables into a MySQL database using PythonThe following SQL code is to perform join on two tables in the database

55