Insert array value to mysql db in php


//get value from a form with comma separated
$formValues = $_POST['prtype'];

//make array be comma delimeter
$alltype = explode(',' ,$formValues);

//use serialize function to put that value to mysql database
$newValues = serialize( $alltype);


//insert into database
$sql = "mysqli_query( col1, col2 ) VALUES ('val1', ' ".$newValues." ' )";
mysqli_query($conn, $sql);



//get the data from database
$query_result = mysqli_query($conn, "SELECT * FROM products where p_id = '6' ");
$row = mysqli_fetch_assoc($query_result);

//it return the array
$retrieved_value = unserialize($row['col2']);

Post a Comment

0 Comments