1
   //This is my html code 
   //ajtest.html:
   <html lang = "en " ng-app>
   <head>
   <title>Testing database with angular js</title>
   <style>
   input.ng-invalid(border:1px solid red;}
   </style>
   </head>
   <body>
   <form action ="ajdbtest.php" method = 'post'>
   username : <input type = "text"  name = 'uname' ng-model="user.uname"  required>
   password : <input type = "password" name = 'pass' ng-model="user.pass"  required>
   <tr>
   <td> Email ID</td>
   <td><input type="email" name="prid" value="" ng-model = "user.prid" required /></td>
   <td><input type="email" name="paid" value="" ng-model = "user.paid" required /></td>
   </tr>
  <tr>
  <input type = 'submit' value = "submit">
  </form>
  </body>
  </html>

  //here is my php code :
  <?php 
  $data = json_decode(file_get_contents("php://input"),TRUE);
  $uname = mysql_real_escape_string($data->uname);
  $pass= mysql_real_escape_string($data->pass);
  echo $uname;
  echo $pass;    
  ?>

errors are : Notice: Trying to get property of non-object in C:\xampp\htdocs\ajdbtest.php on line 5

Notice: Trying to get property of non-object in C:\xampp\htdocs\ajdbtest.php on line 6 WHat is Happenening here I am a new bie please help me out ..

1 Answers1

0

Since you are POSTing a form there is not JSON data to read and decode (so $data is not an object).
Instead, there data can be accessed through the $_POST super global:

<?php 
$uname = mysqli_real_escape_string($_POST["uname"]);
$passcc= mysqli_real_escape_string($_POST["pass"]);

Notice I used mysqli_real_escape_string, because you really should not use mysql_* functions.

Community
  • 1
  • 1
gkalpak
  • 47,844
  • 8
  • 105
  • 118
  • When to use that joson decode ? can u provide me any sort of references so that i can learn AJ in a better way, Thank for the help appreciate a lot – Bharadwaj_Turlapati Apr 18 '14 at 06:45
  • Why do you want to use `json_decode` ? It is not obligatory, you know. You should use it when there is JSON data to decode. (E.g. the `$http` service posts JSON-encoded data by default). If by AJ you mean AngularJS you can start with the official tutorial (it's kind of amazing). And the docs have been incredibly improved lately, so they are a pretty descent resource. Other than that there are plenty of tutorials out there - I can't really recommend any: read them all and then you'll know which ones were good :D (`egghead.io`'s video tutorials are a good introduction as well). – gkalpak Apr 18 '14 at 07:09