I have the following array which I would like to insert into mysql database.
- Item[0] = Soccer
- Item[1] = Rugby
- Item[2] = Football
- Item[3] = Netball
- Item[4] = Hockey
I am using the following function to insert into the database, located in functions.php:
//Capture items
function item($register_data)
{
array_walk($register_data,'array_clean');
$fields = ' '.implode(',',array_keys($register_data)).' ';
$data = '\''.implode('\',\'',$register_data).'\'';
//Insert user Data into the database
$query = "INSERT INTO items ($fields) VALUES ($data)";
mysql_query($query);
}
Now this is how I insert:
for($i =0;$i<4;$i++)
{
$item = array($i = item[i]);
}
//Call the function to insert into the database
item($item);
This method doesn't seem to work. Please assist
mysql_error()to get hints to what went wrong. 2) Switch to mysqli or PDO asmysql_xfunctions are deprecated.mysql_*is deprecated... Check into PDO or MySQLi.echoquery. And see if it a validSQL.