$value ) { $string .= "$key = ". checkSQLValues ( $value ).", "; } // remove last comma $string = substr ( trim( $string ), 0, strlen ( trim ( $string ) ) -1 ); // build the where clause portion of the Update SQl Statement. if ( !empty ( $where ) ) { if ( !is_array ( $where ) ) trigger_error ( "where value must be an array", E_USER_ERROR ); $string .= " where "; foreach ( $where as $key => $value ) $string .= "$key ".checkSQLValues ( $value )." and "; $string = substr ( $string, 0, strlen ( $string ) - 5 ); } return $string; } // end sql_create_update //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// function checkSQLValues ( $value ) { $value = trim($value); // checks for NULL values for date and times if ($value=="NULL") return $value; //otherwise return return "'" . addslashes($value) . "'"; } // end checkSQLValues //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// function sql_create_insert( $table, $fields ) { if ( !is_array ( $fields ) ) { echo "Value for sql insert must be an array"; exit; } $string = "insert into $table"; $SQLfields = ""; $SQLvalues = ""; foreach ( $fields as $key => $value ) { $SQLfields .= "$key, "; $SQLvalues .= checkSQLValues ( $value ) . ","; } $SQLfields = substr ( trim ( $SQLfields ), 0, strlen( trim ( $SQLfields ) ) -1 ); $SQLvalues = substr ( trim ( $SQLvalues ), 0, strlen( trim ( $SQLvalues ) ) -1 ); $string .= " ($SQLfields) values ($SQLvalues);"; return $string; if ( !$this->__Result = @mysql_query ( $string, $this->__Id ) ) { $this->__ErrorsMessages ( "Insert query execution", $string, mysql_errno ( ), mysql_error ( ) ); return false; } $this->RowsAffected = @mysql_affected_rows ( ); $this->LastInserted = @mysql_insert_id ( ); if ( empty ( $this->RowsAffected ) ) return false; else return true; } // sql_Create_Insert ?> Athens Patient Survey