I'm having a total buzz kill here.
I'm trying to get a result from a query with mysql_fetch_array() but its bringing the from value. Here's a quick example:
This is the query:
$query = SELECT COUNT(*) AS total FROM rese WHERE usua_cod = '{$user_cod}';
This is the query output on the "database tool":

This is the PHP code:
$sql_check = mysql_query($query) or die( mysql_error());
if($sql_check)
{
$result_check = mysql_fetch_array($sql_check);
if($result_check[0] > 0)
{
//Erro
$Result = array('Resultado'=>"NO",
"msg"=>"Você já possui uma reserva neste horário",
'debug'=>$result_check[0],
'query'=>"$query",
'res1'=>$result_check);
$arrayOfChildren[] = $Result;
$myJSON = json_encode($arrayOfChildren);
echo($myJSON);
}
else
{
// DOES THE INSERT CODE
}
}
On the Xcode console I get this:
2014-11-26 21:10:00.784 ezmall[1250:423465] dict : (
{
Resultado = NO;
debug = 1;
msg = "Voc\U00ea j\U00e1 possui uma reserva neste hor\U00e1rio";
query = "SELECT COUNT(*) AS total FROM rese WHERE usua_cod = '{$user_cod}'";
res1 = {
0 = 1;
total = 1;
};
}
)
So I thinks there's something kind of messed up because the "0" thats on "res1" should be the result for the "total" and not an index. So, any thoughts?
Cheers.
var_dump($sql_check);prints? And do you see that big red box on the manual, it is there for a reason ;)$_POSTdata directly into the query: it creates a gigantic SQL injection bug.mysql_queryis an obsolete interface and should not be used, it's being removed from PHP. A modern replacement like PDO is not hard to learn. A guide like PHP The Right Way explains best practices.