1

this is my php code:

    <?php 
    //Creating a connection
    $con = mysqli_connect("****","****","****","****");
    $con->set_charset("utf8");

    if (mysqli_connect_errno())
    {
       echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $strcode = $_GET["id"];

    $sql = "Select movie_image from map_table2 where movie_image = '".$strcode."' ORDER BY id DESC LIMIT 1 ";

    $result = mysqli_query($con ,$sql);

    while ($row = mysqli_fetch_assoc($result)) {

        $array[] = $row;

    }
    header('Content-Type: text/html; charset=utf-8');

    echo json_encode($array, JSON_UNESCAPED_UNICODE );

    mysqli_free_result($result);

    mysqli_close($con);

?>

When I run the php, I get this data:

[{"movie_image":"231320166"}]

But I want to get this data:

231320166

What code should I use?

Farshad.A
  • 41
  • 4
  • 2
    You json encode it (but don't set the proper header), if you just want the data you can `echo $array[0]['movie_image'];` – Qirel Sep 25 '17 at 09:47
  • You're already using an API that supports **prepared statements** with bounded variable input, you should utilize parameterized queries with placeholders (prepared statements) to protect your database against [SQL-injection](http://stackoverflow.com/q/60174/)! Get started with [`mysqli::prepare()`](http://php.net/mysqli.prepare) and [`mysqli_stmt::bind_param()`](http://php.net/mysqli-stmt.bind-param). – Qirel Sep 25 '17 at 09:48
  • @Qirel i try this code, but get noting! – Farshad.A Sep 25 '17 at 09:51

2 Answers2

1

replace:

json_encode($array, JSON_UNESCAPED_UNICODE );

with:

echo $array[0]['movie_image'];
Calimero
  • 4,238
  • 1
  • 23
  • 34
1

Use json_decode() http://php.net/manual/en/function.json-decode.php

<?php

$json = '[{"movie_image":"231320166"}]';
$array = json_decode($json, true);
$image = $array[0]['movie_image'];
echo $image;

See it here https://3v4l.org/lrnL6

delboy1978uk
  • 12,118
  • 2
  • 21
  • 39