\doxysection{registrar\+Voto.\+php}
\hypertarget{registrarVoto_8php_source}{}\label{registrarVoto_8php_source}\index{api/registrarVoto.php@{api/registrarVoto.php}}
\mbox{\hyperlink{registrarVoto_8php}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00001}00001\ <?php}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00002}00002\ }
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00025}00025\ \textcolor{comment}{//\ Conecta\ com\ o\ banco\ de\ dados}}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00026}00026\ require(\textcolor{stringliteral}{'connect.php'});}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00027}00027\ }
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00052}00052\ \mbox{\hyperlink{registrarVoto_8php_a1a37d7994caf19ad5a87ac643651e578}{\$votos}}\ =\ json\_decode(file\_get\_contents(\textcolor{stringliteral}{'php://input'}))-\/>votos;}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00053}00053\ }
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00054}00054\ \textcolor{comment}{//\ Registra\ os\ votos\ no\ banco\ de\ dados}}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00055}00055\ \textcolor{keywordflow}{foreach}\ (\mbox{\hyperlink{registrarVoto_8php_a1a37d7994caf19ad5a87ac643651e578}{\$votos}}\ as\ \$v)\ \{}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00056}00056\ \ \ \ \ \textcolor{comment}{//\ Voto\ branco\ ou\ nulo}}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00057}00057\ \ \ \ \ \textcolor{keywordflow}{if}\ (empty(\$v-\/>numero)\ or\ is\_null(\$v-\/>numero))\ \{}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00058}00058\ \ \ \ \ \ \ \ \ \$numero\ =\ \$v-\/>etapa\ ===\ \textcolor{stringliteral}{"{}prefeito"{}}\ ?\ \textcolor{stringliteral}{"{}nulop"{}}\ :\ \textcolor{stringliteral}{"{}nulov"{}};}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00059}00059\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00060}00060\ \ \ \ \ \ \ \ \ \$numero\ =\ \$v-\/>numero;}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00061}00061\ \ \ \ \ \}}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00062}00062\ }
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00063}00063\ \ \ \ \ \$query\ =\ sprintf(}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00064}00064\ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}UPDATE\ \`{}Candidato`}}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00065}00065\ \textcolor{stringliteral}{\ \ \ \ \ \ \ \ SET\ \`{}votos`\ =\ votos\ +\ 1}}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00066}00066\ \textcolor{stringliteral}{\ \ \ \ \ \ \ \ WHERE\ \`{}titulo`\ =\ '\%s'\ and\ numero\ =\ '\%s'"{}},}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00067}00067\ \ \ \ \ \ \ \ \ mysqli\_real\_escape\_string(\mbox{\hyperlink{connect-local_8php_aa8a5a87b9c1a6a0819b88447cbe41877}{\$conn}},\ \$v-\/>etapa),}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00068}00068\ \ \ \ \ \ \ \ \ mysqli\_real\_escape\_string(\mbox{\hyperlink{connect-local_8php_aa8a5a87b9c1a6a0819b88447cbe41877}{\$conn}},\ \$numero)}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00069}00069\ \ \ \ \ );}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00070}00070\ }
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00071}00071\ \ \ \ \ \textcolor{comment}{//\ Retorna\ erro\ caso\ a\ query\ falhe}}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00072}00072\ \ \ \ \ \textcolor{keywordflow}{if}\ (!\mbox{\hyperlink{connect-local_8php_aa8a5a87b9c1a6a0819b88447cbe41877}{\$conn}}-\/>query(\$query))\ \{}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00073}00073\ \ \ \ \ \ \ \ \ http\_response\_code(207);}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00074}00074\ \ \ \ \ \ \ \ \ echo\ (\textcolor{stringliteral}{"{}Erro\ ao\ registrar\ voto\ de\ "{}}\ .\ \$v-\/>etapa\ .\ \textcolor{stringliteral}{"{}<br>"{}});}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00075}00075\ \ \ \ \ \};}
\DoxyCodeLine{\Hypertarget{registrarVoto_8php_source_l00076}00076\ \}}

\end{DoxyCode}
