mysqli - PHP Not inserting record due to Null id

Solution:
Your functions are slightly off.
function addRecord($table,$coloumn,$values){
$insertQuery = "INSERT INTO ".$table." VALUES('".$values."')";
}
This does not return anything, also, the variable$coloumn
is never used.
I cannot see where your actual mysql insert is happening, but as that function doesn't do anything except assign a string to a variable, it cannot do anything.
It's given me warning because of i passed NULL in $values array so during add record it's display
You are calling this function asaddRecord('employee',$val);
, and as you can see, you are passing$val
where$coloumn
should be, remove$coloumn
from the function, and that warning will go away
Also
$columns= array('id','employee_name','employee_salary','employee_age');
$values =array(NULL,'Jack','12000','15');
should be
$columns= array('employee_name','employee_salary','employee_age');
$values =array('Jack','12000','15');
Then:
function addRecord($table,$values){
return "INSERT INTO ".$table." VALUES('".$values."')";
}
$addQuery = addRecord('employee',$val);
and use$addQuery
in your statement.
1136 - Column count doesn't match value count at row 1
This is because you are not specifying which columns to insert, and MySQL knows that there are 4 columns, including the ID, and you are giving it three values.
Your query should be:
INSERT INTO employee (employee_name, employee_salary, employee_age) VALUES('Jack','12000','15');
Answer
Solution:
Change :
$columns= array('id','employee_name','employee_salary','employee_age');
$values =array(NULL,'Jack','12000','15');
to
$columns= array('employee_name','employee_salary','employee_age');
$values =array('Jack','12000','15');
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: target class [commandmakecommand] does not exist.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.