i want to insert my array data to database in one column.
my column in database is id(auto increment)
& datas
.
here what i try, i get error.
i want my data like this
id(primary)(AI)(INT) datas(varchar:255)
-------- ----
1 3001182708
2 3001182713
3 3001183215
im try using this answer https://stackoverflow.com/a/10054725/9661872
$rand_post = ["3001182708", "3001182713", "3001183215", "3001183558", "3001183753"];
$prep = array();
foreach($rand_post as $k => $v ) {
$prep[':'.$k] = $v;
$sth = $db->prepare("INSERT INTO tes (`datas`) VALUES (" . implode(', ',array_keys($prep)) . ")");
$res = $sth->execute($prep);
}
Fatal error: Uncaught PDOException: SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1 in C:\xampp\htdocs\savelink\index.php:23 Stack trace:
0 C:\xampp\htdocs\savelink\index.php(23): PDOStatement->execute(Array) #1 {main} thrown in
C:\xampp\htdocs\savelink\index.php on line 23