class loading problem

hi all,

i have a problem with class loading. i got a file called autoInsert.php (connection function, insert and update function).
[php]
include(‘autoInsert.php’);
$a= new autoInsert();
$a->Connect();
$a->Insert();

//and the other part of codes
[/php]

but this doesnt work…

There is nothing wrong with your syntax. There is probably something wrong with your class.

this is the class. i have checked and rechecked but i havent seen any error…

[php]

class autoInsert{
var $db_conn;

	function Connect($user, $pass, $host){
		if ($this->db_conn = mysql_connect($host, $user, $pass)){
			return true;	
		}else{			
			echo mysql_error();
			return false;
		}
	}
	
	function iSelect($db){
		if (mysql_select_db($db)){
			return true;
		}else{			
			echo mysql_error();
			return false;
		}
	}

function Insert($table=array(), $postData = array()){
for($i=0; $i<sizeof($table); $i++){
$q = "DESC $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 $table[$i] ($fields) VALUES ($values)";
	       mysql_query($q1);
				
	}
  }
  return;
}
	function Update($table, $postData = array(), $conditions = array()){
		$q = "DESC $table";
		$q = mysql_query($q);
		
		$getFields = array();
		
		while ($field = mysql_fetch_array($q)){
			$getFields[sizeof($getFields)] = $field['Field'];
		}
		
		$values = "";
		$conds = "";
		
		if (sizeof($getFields) > 0){
			foreach($getFields as $k){
				if (isset($postData[$k])){		
					$postData[$k] = htmlspecialchars($postData[$k]);
					
					$values .= "`$k` = '$postData[$k]', ";
				}
			}
			
			$values = substr($values, 0, strlen($values) - 2);
			
			foreach($conditions as $k => $v){
				$v = htmlspecialchars($v);
			
				$conds .= "`$k` = '$v'";
			}
			
			$update = "UPDATE $table SET $values WHERE $conds";				
											
			if (mysql_query($update)){
				return true;
			}else{
				echo mysql_error();
				return false;
			}
		}else{
			return false;
		}
	}

	function Disconnect(){
		if (mysql_close($this->db_conn)){
			return true;
		}else{		
			echo mysql_error();	
			return false;
		}
	}
	
}

?>
[/php]

I assume you are passing the values to Connect() and Insert()?

I don’t see any syntax problems so you will just need to go through and debug. Make sure you have display_errors = On and error_reporting = E_ALL

thanks buddy!

Sponsor our Newsletter | Privacy Policy | Terms of Service