simple sql insert function in php

php function :
function insertSQL($post, $exvar, $table)
foreach($post as $key=>$val){
if( !in_array($key, $exvar) ){
$sql = “insert into $table (“.implode(“,”,$fld).”) values (“.implode(“,”,$vlu).”)”;
return $sql;
if($submit) {
$ex = array(‘submit’=>’submit’,’reset’=>’reset’);
echo insertSQL($data,$ex, ‘tableUser’);

html :

<form method=”post”>

<input type=”text” name=”name”>

<input type=”text” name=”middlename”>

<input type=”submit” name=”submit” value=”submit”>


p/s: no input validation… html form, the name of the input must be the same with the name of the column/field in tables.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s