Hey All
Im just got started with OOP and having some trouble inserting form data into mysql table.
I store all the the form data in a variable eg: $field_array and pass it to a function called 'tableInsert'. Then I loop through the array and construct the insert query.
The above works fine. My problem is that the form data get stored in two different tables and that all the data is located in a single array. How can I loop through the array and insert it into two different tables.
I hope the above made sense. Below is the code i use.
$field_array = "$HTTP_POST_VARS"; //gets form data
$tableFunction = new tableFunctions();
$tableFunction-> tableInsert("tbl_agent_general",$field_array);
//class code follows below
class tableFunctions extends dbConnection
{
var $tableName;
var $fieldsArray;
function tableInsert($tableName,$fieldsArray)
{
$this->tableName = $tableName;
$this->fieldsArray = $fieldsArray;
$sql_query = "INSERT INTO $tableName SET ";
while(list($key, $value) = each($fieldsArray))
{
$sql_query .= "$key = '$value', ";
echo "$key = $value<br>";
}
$sql_query = rtrim($sql_query, ', ');
mysql_query($sql_query,"$this->dbcnx") or die(mysql_error());
}
}
I have have searched around and cant find anything. If anybody can help, I will greatly appreciate it.
Thanks