<?php

function insertVal($table, $dataInfo, $successmsg, $errormsg){
global $conn; 
$fields = implode(", ", array_keys($dataInfo)); 
$val = implode("','", array_values($dataInfo));

$insVal = $conn->query("insert into " . $table . "(". $fields.") values ('".$val."')");
if($insVal!=null){
return $successmsg;
}else{
return $errormsg;
}
}



function selData($table, $field, $crit, $key_id){
global $conn; 

$selinfo = $conn->query("select * from " . $table . "  where " . $field . " = '" . $crit . "' order by " . $key_id . " DESC");
return $selinfo;
}

function updateData($table, $data, $field, $crit){
global $conn; 
					$arrKeys = array_keys($data);
					$arrVal = array_values($data);			  
					$num = count($arrVal)-1;
			       for($i=0; $i<=$num; $i++){
				   $arrData[] = "$arrKeys[$i] = '$arrVal[$i]'"; 
				   }
			 $fields = implode(", ", $arrData);	   
			 
$upData = $conn->query("update ". $table . " set ". $fields . " where " . $field." = '" . $crit ."'");		
return $upData;
 }

?>