mysqli - Would this PHP inserting be secure? -
this question has answer here:
- how can prevent sql injection in php? 28 answers
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.
Comments
Post a Comment