未定义的属性:第7行的C:\ wamp64 \ www \ try \ insert.php中的stdClass :: $ ecompany

时间:2017-10-25 06:46:11

标签: php stdclass

<?php 
$conn = mysqli_connect("localhost", "root", "", "mydb"); // Database Connection 
$data = json_decode(file_get_contents("php://input"));// Decoding data
echo '<pre>'; //Printing Array
print_r($data); 
echo '</pre>';
//Getting values in variables
$ename = mysqli_real_escape_string($conn,$data->ename);
$eemail = mysqli_real_escape_string($conn, $data->eemail);
$ecompany = mysqli_real_escape_string($conn, $data->ecompany);
$edesignation = mysqli_real_escape_string($conn, $data->edesignation);
// Inserting values into Database
mysqli_query($conn, "INSERT INTO employee('name', 'email', 'companyName','designation') VALUES('".$ename."','".$eemail."','".$ecompany."','".$edesignation."')");
?>    

数组输出为 - stdClass Object([ename] => Rohit [eemail] =>xxxxxxx@gmail.com [ecompanyname] => Seven [edesignation] => Web & Graphic Designer)

请帮助我,我现在能做什么? 什么是stclass ??

非常感谢

2 个答案:

答案 0 :(得分:0)

您正试图获得&#34; ecompany&#34;,但这不存在。 spec/features/login_spec.rb

在对象中称为&#34; ecompanyname&#34;。

所以: $ecompany = mysqli_real_escape_string($conn, $data->ecompany);

可以在What is stdClass in PHP?

找到stdClass的说明

答案 1 :(得分:0)

实际上答案就在你的问题中。 print_r()语句的输出为:

0b

这意味着您的输出对象在第7行中使用 ecompanyname 而不是 ecompany $ data-&gt; ecompany

所以请将第7行更改为:

Array Output is - stdClass Object([ename] => Rohit [eemail] => xxxxx@gmail.com [ecompanyname] => Seven [edesignation] => Web & Graphic Designer)

这就是全部!