$value) { $post_string .= "$key=$value&"; } write_to_log($post_string); // Get the meta information $action = $_POST['_ACTION']; $table = $_POST['_TABLE']; $id_field = $_POST['_IDFIELD']; $id_value = $_POST['_IDVALUE']; // What are we doing? // Note that there is no "UPDATE" action. To update a record, first send a "DELETE" request, then an "INSERT" request. switch ($action) { case 'Delete': // Start the SQL $sql = "DELETE FROM $table WHERE "; // Split the ID fields and values up (in most cases, this will result in just a one-element array) $id_fields = explode(',', $id_field); $id_values = explode(',', $id_value); // Loop through and tack on the WHERE clauses for($x = 0; $x < count($id_fields); $x++) { $sql .= $id_fields[$x] . ' = ' . $id_values[$x] . ' AND '; } // Lop off the last " AND " $sql = substr($sql, 0, -5); break; case 'Insert': // Run through the fields and wrote some SQL foreach($_POST as $key => $value) { if(substr($key, 0, 1) != '_') { // Do we need to take a custom action for this field? if ($custom[$table][$key]) { $value = $custom[$table][$key]($value); } $fields .= "$key, "; $values .= "'$value', "; } } // Trim off the ends $fields = substr($fields, 0, -2); $values = substr($values, 0, -2); // Complete the SQL $sql = "INSERT INTO $table ($fields) VALUES ($values)"; break; } // Write the SQL to the log write_to_log("SQL Generated: $sql"); // Make the connection $conn = mysql_connect($db['host'], $db['user'], $db['password']); mysql_select_db($db['database']); mysql_query($sql); write_to_log('Error: ' . mysql_error()); write_to_log("\n\n\n"); // Close the log fclose($log); // Writes a text string to the log file function write_to_log($text) { $log_data = false; if($log_data) { global $log; $log_time = date('m/d/Y h:m:s'); fwrite($log, "$log_time: $text\n"); } } ?>