Jump to content

Problem with Josn Data


NebuJohn

Recommended Posts

I have recived a set of dat from an android device using Json. I have decoded this data into a PHP array. I took each value of the array usinf foreach and placed in a MySQL statement. But its not working. Can any body help me. Given below is my code.

       	$array=$_POST['nuer']; //numbers fetched 

        $jstring = (array)json_decode($array);
 
        foreach($jstring  as $value ) //loop over values
         {

         
         $four = mb_substr($value, 0,-10); //to get the first chara's
         $ten = mb_substr($value, -10); // to get the last ten chara


               $con=mysqli_connect("localhost","app","test","appt"); //connection to the database

	       $result = mysqli_query($con, "SELECT * FROM profile WHERE (mobileno IN '$ten') AND (code IN '$four')");
               while($row = mysqli_fetch_array($result, MYSQL_ASSOC))
                {

                $friend[] = $row[id];

                }
               mysqli_close($con);

$result is returning a null value. When i used a user defined array with random value, this code worked perfectly. Thanks in Advance.

Link to comment
Share on other sites

$result is returning a null value.

Uh, no? It's either a mysqli_result object or false.

 

The object probably isn't in the form you expect it to be. What does

print_r($jstring);
output?

 

Oh, and

$jstring = (array)json_decode($array);
Don't do that when json_decode() can give you an array directly.

$jstring = json_decode($array, true);
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.