Forum Moderators: coopster
How can I save this data into mySQL and how can I view these data from DB?
// FUNCTION
function check1($var){if(!preg_match("/[^A-Za-z]/",$var)) {return TRUE;} else {return FALSE;}}// CHECK POST VALUE EXIST
if(isset($_POST["colors"])) {$colors=$_POST["colors"];
// IF YES, COUNT ARRAY
$nb_colors=count($colors);
// MAKE SURE THAT EVERY VALUE OF THE ARRAY IS [a-z]
for ($i="0"; $i<$nb_colors; $i++) {
if(!check1($colors[$i])) {$colors[$i]="";}} unset($nb_colors);}
// IF NOT, ARRAY NULL
else {$colors=array();}
OK, you have your array checked and safe for SQL, you can implode the array for insertion in your database
$colors = implode("-", $colors);
$sql = "INSERT INTO $db (`db_id`,`colors`) VALUES (NULL,'$coche')";