Jump to content

Function-Problem


oslo

Recommended Posts

i get problem with 'insert' in this function. logically, i think its ok but....

 

function iInsert($list_tbl=array(), $postData = array()){

$res = count($list_tbl);

for($i=0; $i<$res; $i++){

$q = "DESC $list_table[$i] ";

$q = mysql_query($q);

 

$getFields = array();

 

while ($field = mysql_fetch_array($q)){

$getFields[sizeof($getFields)] = $field['Field'];

}

 

$fields = "";

$values = "";

 

if (sizeof($getFields) > 0){

foreach($getFields as $k){

if (isset($postData[$k])){

$postData[$k] = htmlspecialchars($postData[$k]);

 

$fields .= "`$k`, ";

$values .= "'$postData[$k]', ";

}

}

 

$fields = substr($fields, 0, strlen($fields) - 2);

$values = substr($values, 0, strlen($values) - 2);

 

//$insert = "INSERT INTO $table ($fields) VALUES ($values)";

$q1=" INSERT INTO ($list_table[$i]) ($fields) VALUES ('$values')";

if (mysql_query($q1)){

return true;

}else{

echo mysql_error();

return false;

}

}else{

return false;

}

 

}

return true;

 

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...