insert function PHP mySQL -


i have function in php mysql inserts records database. take in array of decoded json data, field name, connection , db name. builds sql statement , inserts records 1 one, or @ least thats think should do. run everything, make connection, database , table when gets function, fails. feel has insert statement not sure how fix it. appreciated.

function:

function insertrecords($array,$fieldname, $conn, $db_name) {     mysqli_select_db($conn, $db_name);      $sql_insert = "insert `tbl_articles` (`" . $fieldname . "`) values ('" . $records . "')";      foreach ($array $records)     {          if(mysqli_query($conn, $sql_insert))         {             echo "records inserted.";         }         else          {             die('error : ' . mysqli_error($conn) . "<br>");         }     }     echo $sql_insert . "<br>"; } 

it looks query string displaced there. try this:

function insertrecords($array,$fieldname, $conn, $db_name){     mysqli_select_db($conn, $db_name);      foreach ($array $records)     {         $sql_insert = "insert `tbl_articles` (`" . $fieldname . "`) values ('" . $records . "')";         if(mysqli_query($conn, $sql_insert))         {             echo "records inserted.";         }         else          {             die('error : ' . mysqli_error($conn) . "<br>");         }     } } 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -