doushen1026
2017-10-25 06:46
采纳率: 100%
浏览 87
已采纳

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

<?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."')");
?>    

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

Please help me , what can i do now ? What is stclass ??

Thanks alot

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • donglinyi4313 2017-10-25 06:50
    已采纳

    You are trying to get "ecompany", but that does not exist. $ecompany = mysqli_real_escape_string($conn, $data->ecompany);

    In the object it is called "ecompanyname".

    So do: $ecompany = mysqli_real_escape_string($conn, $data->ecompanyname);

    An explanation of stdClass can be found here What is stdClass in PHP?

    已采纳该答案
    打赏 评论
  • doutiaoku4495 2017-10-25 06:51

    Actually the answer was in your question. The output of print_r() statement is:

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

    So that means your output object has ecompanyname instead of ecompany as using in the 7th line: $data->ecompany

    So please change the 7th line to:

    $ecompany = mysqli_real_escape_string($conn, $data->ecompanyname);
    

    That's all!

    打赏 评论

相关推荐 更多相似问题