php - Insert multiple value isn't working -


this question exact duplicate of:

i'm trying write code multiple insert value isn't working. error warning: invalid argument supplied foreach(). appreciate.

if (isset($_post['mul_pr'])) { $counter = $mysqli->real_escape_string($_post["counter"]); $pr = $mysqli->real_escape_string($_post["pr"]); $pr_qty = $mysqli->real_escape_string($_post["pr_qty"]); $unit = $mysqli->real_escape_string($_post["unit"]); $pr_date = $mysqli->real_escape_string($_post["pr_date"]); $gss_date = $mysqli->real_escape_string($_post["gss_date"]); $request = $mysqli->real_escape_string($_post["requested"]); $approve = $mysqli->real_escape_string($_post["approved"]); $desig_r = $mysqli->real_escape_string($_post["designation_r"]); $desig_a = $mysqli->real_escape_string($_post["designation_a"]); $year = $mysqli->real_escape_string($_post["year"]); $pr_id = $mysqli->real_escape_string($_post["pr_id"]);      if (count($counter > 0))     {         $new = array();         foreach ($counter $key => $value)         {             $new[] = "('" . $counter . "', '" . $pr . "', '" . $pr_qty . "', '" . $unit . "','" . $pr_date . "', '" . $gss_date . "', '" . $request . "', '" . $approve . "'             , '" . $desig_r . "', '" . $desig_a . "', '" . $year . "', '" . $pr_id . "')";         }         if (count($new) > 0)         {             $result = $mysqli->query("insert purchase_request (counter, pr, total_quantity, unit, pr_date, gss_date, requested, designation_r, approved, designation_a,year,pr_id)             values " . implode(', ', $new));          }     } } 

firstly error here:

if (count($counter > 0)) 

it should

if (count($counter) > 0) 

you might warning because count($counter) 0 , due forged if condition, might execute loop on non or empty array hence error


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -