php - how to insert array of data into database -


here code-

$things = mysql_real_escape_string(implode(',', $_post['things']),$link);  $q = "insert tblslider(src) values ('".$things."')"; print_r($q); $result = $mysqli->query($q) or die(mysqli_error($mysqli)); 

but query getting generated insert tblslider(src) values ('4368122.jpg,5440051.jpg,1047428.jpg') should insert tblslider(src) values ('4368122.jpg'),('5440051.jpg'),('1047428.jpg') thats why taking 1 record not three.

you do:

$things = array_map('mysql_real_escape_string', $_post['things']); $q = "insert tblslider(src) values ('". implode("'),('", $things)."')"; 

it generates (with test data):

insert tblslider(src) values ('a.jpg'),('b.jpg'),('c.jpg') 

i forgot: use functions mysql_real_escape_string on real data, not sql string. in example apply function on concatenated data.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -