I have this frustrating problem, i am using a for loop to insert data into a database, the data is inserting into the DB, but it is only inserting the first character, for example instead of inserting the word example, it will only insert the letter e. See screenprint below:
enter image description here The top row is a example row
This is my first time using a for loop, so i was wondering if it something i have missed out in my code, which is causing this problem.
Code
$_query = array();
for ($x = 0; $x < count($OI); $x++) {
$_query = "INSERT INTO ord_dets(Order_ID,custmer_ip,Resturant_ID,Resturant_name,City_name,
Product_Id,Product_Name,Product_Price,item_sub)
VALUES ('" . $OI[$x] . "', '" . $ip[$x] . "','" . $_SESSION['rest_id'][$x] . "','" . $rest_name[$x] . "',
'" . $City_name[$x] . "','" . $Product_Id[$x] . "','" . $product_name[$x] . "','" . $prod_price[$x] . "','" . $item_sub[$x] . "')";
}
$query_run = $dbc->prepare($_query);
echo $_query;
if (!$query_run->execute()) {
$insertError = "There was an error inserting data: " . $query_run->error;
print "affected rows:" . $query_run->affected_rows; //how many records affected?
}
}
}