function problem

[php]
function iInsert($list_tbl=array(), $postData = array()){
$res = count($list_tbl);
for($i=0; $i<$res; $i++){
$q = "SHOW $list_table[$i] ";
$q2 = mysql_query($q);

		$getFields = array();
		
		while ($field = mysql_fetch_array($q2)){
			$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);
			
	              $q1=" INSERT INTO $list_table[$i] ($fields) VALUES ('$values')";		
			mysql_query($q1);
		}
	
    }
	return true;
}	

[/php]

i get no error and no insert to db. i think logically its ok but it doesnt work…

There is no way for us to know if your query is returning any results. You should just go through and debug.

For example:

[php]
while ($field = mysql_fetch_array($q2)){
$getFields[sizeof($getFields)] = $field[‘Field’];
}

// debug
var_dump($getFields);
return;
[/php]

you are right! i get no results from the query.

thanks a lot!

Sponsor our Newsletter | Privacy Policy | Terms of Service