i apologize if the question is wrong. i am a still a newbie and a learner however i would appreciate if someone correct me if i am somewhere wrong.
here in the Class method i am using for Inserting the data into the database
public function insert($table,$col,$value)
{
if(is_array($col) && is_array($value))
{
$query = "INSERT INTO ".$table."(" . implode(",",$col) . ") VALUES(" . implode(",",$value) . ")";
}
else
{
$query = "INSERT INTO " . $table . "(" . $col . ") VALUES(". $value . ")";
}
}
now here i am determining if the $col and $value is an array if yes then process it.
however i have a problem here since the VALUES in the Insert statement needs to be represnted in the single or double quote format it will not process the query and hence print the error
for example the below code would print the error
$query = "INSERT INTO users(username,email) VALUES(test,test@test.com)";
and the correct format will be
$query = "INSERT INTO users(username,email) VALUES('test','test@test.com')";
now in the col value i would like to add the single quotes to every value in the array for example the $value array which is like this.
$value = array(‘test’,’test@test.com’);
should give back the value
‘test’,’test@test.com’
instead of
test,test@test.com
how do i achieve it?
Make sure that neither $col nor $value is empty.