2017-07-07 85 views
0

我想要一些JSON數據發送到我的服務器端的PHP代碼,但我得到一個錯誤的消息處理:高級JSON對象在PHP

注意:試圖讓非對象的財產 C:\ xampp \ htdocs \ registration.php在xy行。

這是我的Json對象。我想要的東西來處理:

registrationInputData:{"page1":{"regfnev":"John","reglnev":"Kerry","regemail":"[email protected]","regpassword":"Qwerty01"},"page2":{"regtelepules":"Budapest","regirsz":"1123","regutca":"","reghazszam":"","regemelet":"","regajto":"","regtelszam":""},"page3":{"regprofilimage":"dogProfileImage","regfeltetel":true}} 

這裏是我的PHP:

<?php 
session_start(); 
$conn = mysqli_connect("localhost", "root", "", "getpet"); 
mysqli_set_charset($conn, "utf8"); 
$result = false; 

if(isset($_POST['registrationInputData'])){ 
$registrationInputData = json_encode($_POST['registrationInputData']); 

///page1 
$fname = $registrationInputData->page1->regfnev; 
$lname = $registrationInputData->page1->reglnev; 
$email = $registrationInputData->page1->regemail; 
$password = md5($registrationInputData->page1->regpassword); 

$emailquery = "SELECT email FROM users WHERE email = '".$email."'"; 
$emailsql = mysqli_query($conn, $emailquery); 
if(mysqli_num_rows($emailsql) == "0"){ 

    ///page2 
    $settlement = $registrationInputData->page2->regtelepules; 
    $postcode = $registrationInputData->page2->regirsz; 
    $street = $registrationInputData->page2->regutca; 
    $streetnumber = $registrationInputData->page2->regutca; 
    $floor = $registrationInputData->page2->regemelet; 
    $door = $registrationInputData->page2->regajto; 
    $phone = $registrationInputData->page2->regtelszam; 

    ///page3 
    $profilimage = $registrationInputData->page3->regprofilimage; 
    $conditionaccepted = $registrationInputData->page3->regfeltetel; 

    $registrationquery = 
    "INSERT INTO users (fname, lname, email, password, settlement, postcode, street, streetnumber, floor, door, phone, profilimage, conditionaccepted) 
    VALUES ('".$fname."', '".$lname."', '".$email."', '".$password."', '".$settlement."', '".$postcode."', '".$street."', '".$streetnumber."', '".$floor."', '".$door."', '".$phone."', '".$profilimage."', '".$conditionaccepted."')"; 
    $result = true; 
} 
} 
echo $result; 

?> 

感謝您的答案!

+2

'json_encode' __encodes__ json。 'json_decode' __decodes__。 –

+0

oops。你對的 –

+0

問題解決了,謝謝 –

回答

2

如果是json字符串,您需要使用json_decode函數。然後你可以訪問對象元素。