mysqli - Would this PHP inserting be secure? -


this question has answer here:

i've been working on little script insert data database i'm not sure if it's secure way. feedback pretty cool! question, secure way of inserting data?

code:

function dbrowinsert($table, $data) {    require_once('../config.inc.php');       $builddata = null;      $countloop = 1;       foreach($data $field) {           $sep = ($countloop!=count($data) ? ',' : '') ;       if((int)$field == $field) {         $builddata .= (int)$field . $sep;       } else {         $builddata .= '"' .mysqli_real_escape_string((string)$field) . '"' . $sep;       }       $countloop++;      }     $fields = array_keys($data);     mysqli_query($conn, "insert into" . $table . "(`" . implode('`, `', $fields) . "`)                         values('" . $builddata . "')"); } 

the best way use object-oriented style. that's first. second use methods

prepare(), bind(), execute() 

instead of

mysqli_real_escape_string() 

etc.

read in manual, it's simple , find useful , safety.

http://php.net/manual/en/mysqli.prepare.php


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -