I would like to into a string into mysql and understand I have to explode the string into an array before it can be inserted.
How would I write the PHP object oriented code to insert the string?
I have two variables:
$id = "Apple"    and    $product = "Pie, Candy"
This is what I would like the database to look like:
ID          Product
---         -------
Apple       Pie
Apple       Candy
This is what I have written so far in my code:
$id = "Apple";
$product = "Pie, Candy";
$product_arr = explode(", ",$product);
if (is_array($product_arr)) {
    $sql = "INSERT INTO table1 (id, product) VALUES ";
    $value_arr = array();
    foreach($product_arr as $row) {
        $prdct = mysql_real_escape_string($row[0]);
        $value_arr[] = "('$id','$prdct')";
    }
    mysqli_query($conn,$sql);
}
 
     
    
