I want to import data from a CSV to a LaTeX file with the datatool package, but I get error messages like:
Undefined control sequence.
Missing } inserted.
Missing } inserted.
Missing \cr inserted.
Missing { inserted.
Misplaced \crcr.
Extra }, or forgotten \endgroup.
Missing } inserted.
Missing } inserted.
Please what is the problem with this code?
%
% texlive-lang-arabic (for fmultico.sty)
% ttf-arabeyes (for arabic fonts)
\documentclass[a4paper]{article}
\usepackage[a4paper,left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{pdflscape,setspace,amsmath,amssymb}
\usepackage{bidi}
\usepackage{longtable}
%\usepackage{fmultico}
\usepackage{etex}
%\usepackage[postcorrect,noshuffle,insidebox]{automultiplechoice}
\usepackage{amsmath}\usepackage{xltxtra}\usepackage{arabxetex}
\usepackage{datatool}
\DTLloaddb{names}{ph1.csv}
%\usepackage{calligra}
\usepackage{tgschola}
\usepackage{fourier-orns}
\usepackage{graphicx}
\usepackage{wallpaper}
\newfontfamily{\arabicfont}[Script=Arabic,Scale=1]{Rasheeq}
\usepackage[normalem]{ulem}
\usepackage{charter}
\usepackage{microtype}
\hyphenpenalty 100000
\def\signature#1#2{\parbox[b]{1in}{\smash{#1}\vskip12pt}
\hfill \parbox[t]{3cm}{\shortstack{\vrule width 3cm height 0.4pt\\\small#2}}}
\def\sigskip{\vskip0.4in plus 0.1in}
\def\beginskip{\vskip0.5875in plus 0.1in}
\begin{document}
\begin{landscape}
\pagestyle{empty}
\TileWallPaper{1\paperwidth}{1\paperheight}{border-2.jpg}
%=============================%import the data from csv
\DTLforeach{names}{\name=الاسم,\dg=الدرجة,\stunum=A:StudentNum,\subj=subject}{
\noindent{\color{black}\Huge\decoone\decofourleft\hfill\decofourright\decoone\\
\rotatebox[origin=rt]{-90}{\decofourleft}\hfill\rotatebox[origin=lt]{90}{\decofourright}}
{\centering
%=============================% start print the data in pdf
%=============================% print the 1st logo
\noindent
\begin{minipage}[l]{3cm}
\includegraphics[width=.72\linewidth]{moe}
\end{minipage}
\hfill
%%=============================% print the title
\begin{minipage}[c]{6cm}
{\centering
{\onehalfspacing
{\LARGE\bfseries{\textarab{المملكة العربية السعودية}}}\\%\initfamily
{\large\bfseries\textarab{وزارة التربية والتعليم}}\\
{\textarab{جدة}} -- {\textarab{ادارة التربية والتعليم}}\\
\vskip0.4em
{\Large\bfseries\textarab{ثانوية الملك فيصل}}}\\
\par}
\end{minipage}
\hfill
%=============================% print the 2nd logo
\begin{minipage}[r]{3cm}
\includegraphics[width=.92\linewidth]{crown}
\end{minipage}
\vskip1em
%=========%end the logo
%=====%print the header of the content
{\huge\bfseries\textarab{ شهادة شكر وتقدير}}\par {\LARGE\color{black}\decofourleft\quad{\color{black}\decoone}\quad\decofourright}\par
\vskip2em
%=====%print the content with the student name
{\textarab{يسرنا أن نهنئ ابننا الدارس: \name}}\par
{\large\textarab{ على جده واجتهاده ، وحرصه على الارتقاء بمستواه التعليمي والتربوي حيث كانت نتيجته:}}\par}
%============================%print the table
\vspace{-0.3cm}
\begin{center}
\begin{arab}
\begin{minipage}{0.97\linewidth}
\begin{longtable}{|p{5cm}|p{2cm}|p{2cm}|p{3cm}|}
\hline
النسبة المئوية & الدرجة & المادة & رقم الطالب\\
\hline
\subjec & \dg & \subj & \stunum\\[2ex]
\hline
\end{longtable}
\vspace{-0.05cm}
\end{minipage}
\end{arab}
\end{center}
%=======================%end the table
%================%start the end of content
\begin{center}
\textarab{متمنين له دوام التوفيق والنجاح،،}
\end{center}
\vspace{0.5cm}
%==================%start the signature
\noindent
%\beginskip
{\singlespacing
\vfil
\begin{minipage}[c]{4cm}\begin{center}
\sigskip \signature{\textarab{رئيس القسم}}{\textarab{د.عبد الله الصبحي \\ مدير المدرسة }}
\end{center}\end{minipage}
\hfill
\begin{minipage}[r]{4cm}\begin{center}
\sigskip \signature{\textarab{مدرس المادة}}{\textarab{د.سعيد الزهراني \\ مدرس المادة }}
\end{center}\end{minipage}}
%==================%end the signature
\noindent{\color{black}\Huge
\rotatebox[origin=lb]{-90}{\decofourright}\hfill\rotatebox[origin=rb]{90}{\decofourleft}\\
\decoone\rotatebox[origin=c]{180}{\decofourright}\hfill\rotatebox[origin=c]{180}\decofourleft\decoone}
\pagebreak
}
\end{landscape}
\end{document}

\DTLloaddbcommand. You also don't give a sample CSV file. Having Arabic text just makes things more confusing for non Arabic speakers (most of us here), so it might also be helpful to remove that (at least for your column names from the CSV file.) – Alan Munn Apr 17 '12 at 14:12