2016-08-11 87 views
0

我正在用angular和php構建一個項目,而我試圖從phpmyadmin表中刪除一行,並且在php中出現此錯誤。任何人都可以請檢查我的代碼?class stdClass的對象無法轉換爲字符串

<?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); 
    ?> 

使用的var_dump($數據)後:

<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> 
+1

錯誤說的是什麼問題? – Ben

+0

我認爲你在$ data變量中只有var_dump($ data),並在輸出中看到輸出 –

+0

@Ben:$ del =「DELETE FROM file WHERE id =」。$ id; – tanyaa

回答

1

試試這個:

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

是否新的編輯幫助?

+0

謝謝,但仍然一樣沒有錯誤,但不刪除 – tanyaa

+0

@tanyaa你想從哪裏刪除,你有多個表?你的數據庫字段是customer_id,除非customer_id是一個外鍵在文件表中你做錯了。 –

1
json_decode($data, true) 

混合json_decode(字符串$ JSON [,布爾$ ASSOC =假[摘要$深度= 512 [摘要$選項= 0]]])

ACCS當TRUE時,返回的對象將被轉換爲關聯數組。

參見文檔here

相關問題