Sasha Grievus
Sasha Grievus

Reputation: 2686

How to control the result of a json_encode?

i have this simple php code. Locally, with a simple xampp 1.7.3 the echo returns correctly "false" or "true". When i put the code online (on a server, i mean, and i do not have really knowdledge of how the server is made) it returns always "1". Why?

<?php

include "connectionToDb.php";


$nome_utente=$_GET['nome_utente'];

$queryUserAvailable = "SELECT * FROM utente where nome_utente='$nome_utente'";

$rsUserAvailable = connetti($queryUserAvailable);


if(mysql_num_rows($rsUserAvailable) == 0){
$valid=true;

}

else{
$valid=false;

}


echo json_encode($valid);

?>

ConnectionToDb.php

<?php
function connetti($SQL){
$conn = mysql_connect("localhost", "root", ""); //(online this data are obviously different)
$db = mysql_select_db("dbName",$conn);
$risultato = mysql_query($SQL,$conn)
 or die("Query non valida: " . mysql_error());
return ($risultato);
}
?>

Upvotes: 1

Views: 237

Answers (1)

nl-x
nl-x

Reputation: 11832

As it seems from the comments, JSON is not included in the server's PHP configuration. You might want to consult your host and check whether you can include this by just overriding settings via a .htaccess directive

Maybe you can also first try:

if (!extension_loaded('json')) {
    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
        dl('json.dll');
    } else {
        dl('json.so');
    }
}

Upvotes: 1

Related Questions