tanyaa
tanyaa

Reputation: 155

Object of class stdClass could not be converted to string

I'm building a project with angular and php, and I'm trying to delete a row from phpmyadmin table, and I have this error in php. can anyone please check my code?

  <?php
     header('Content-Type: text/html; charset=utf-8');
    $connect=mysqli_connect("localhost", "root", "", "hamatkin");

      include_once 'file.php';
    mysqli_query($connect,"SET character_set_client = utf8");
    mysqli_query($connect,"SET character_set_connection = utf8");
    mysqli_query($connect,"SET character_set_results = utf8");
    // Check connection
    if (mysqli_connect_errno()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $data = json_decode(file_get_contents("php://input"));


     $id = $data->id;
    $del = "DELETE FROM file WHERE id=".$id;

       mysqli_query($connect, $del);

    $newURL = "/hamatkin/#/allPriceOffers";
    header('Location: '.$newURL);
    ?>

after using var_dump($data):

<pre class='xdebug-var-dump' dir='ltr'>
<small>C:\wamp64\www\hamatkin\api\customers-tab\delete-priceOffer.php:43:</small>
<b>object</b>(<i>stdClass</i>)[<i>2</i>]
  <i>public</i> 'id' <font color='#888a85'>=&gt;</font> 
    <b>object</b>(<i>stdClass</i>)[<i>3</i>]
      <i>public</i> 'created' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'2016-08-11 15:19:14'</font> <i>(length=19)</i>
      <i>public</i> 'customer_id' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'85'</font> <i>(length=2)</i>
      <i>public</i> 'full_name' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'אלכס שפירא'</font> <i>(length=19)</i>
      <i>public</i> 'city' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'תל-אביב'</font> <i>(length=13)</i>
      <i>public</i> 'phone' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'545928875'</font> <i>(length=9)</i>
      <i>public</i> 'name' <font color='#888a85'>=&gt;</font> <small>string</small> <font color='#cc0000'>'קורות ×—×™×™×.zip'</font> <i>(length=46)</i>

Upvotes: 0

Views: 913

Answers (2)

godtail
godtail

Reputation: 189

json_decode($data, true)

mixed json_decode ( string $json [, bool $assoc = false [, int $depth = 512 [, int $options = 0 ]]] )

accs When TRUE, returned objects will be converted into associative arrays.

See Document here.

Upvotes: 1

M. I.
M. I.

Reputation: 296

Try this:

$id = intval($data->id->customer_id); 

Does the new edit help?

Upvotes: 1

Related Questions