-2
<?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

Jigar Shah
  • 5,524
  • 2
  • 22
  • 37
Rohit Gautam
  • 179
  • 13
  • 1
    You should not share actual email address while posting code :) – Jigar Shah Oct 25 '17 at 06:52
  • Mean this is no **property ecompany** in your $data->ecompany –  Oct 25 '17 at 06:56
  • yes your are right @jigar Shah – Rohit Gautam Oct 25 '17 at 07:06
  • @RohitGautam please avoid asking such questions, try to understand the basics before asking that would be better for your knowledge and future as well. You have asked what is stdClass => you can understand about the same here : https://stackoverflow.com/questions/931407/what-is-stdclass-in-php#992654 – Adesh Pandey Oct 25 '17 at 07:14
  • @Adesh Pandey yes you are right. i was only stuck on that problem. thanks for your reply – Rohit Gautam Oct 25 '17 at 07:24

2 Answers2

0

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?

Pascal
  • 394
  • 1
  • 12
0

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!

Jigar Shah
  • 5,524
  • 2
  • 22
  • 37
Noat Tran
  • 92
  • 6