anaya

  • Apr 23, 2020
  • Joined Apr 23, 2020
  • In php

    Weedpacket
    Thank you for your answer, I have tried what you said. Simply I want to get input from the user in a browser and after that encode into JSON formate to display it on screen but accordingly, it shows that your data is inserted but still I'm getting empty row in the database. Will you please provide me the code accordingly to let me know where changes are required.

    • In php

      Greetings!
      I am getting this error and won't be able to resolve it.
      **Notice: Undefined index: usname in C:\xampp\htdocs\Mytestsite\api\student_insert.php on line 2

      Notice: Undefined index: pass in C:\xampp\htdocs\Mytestsite\api\student_insert.php on line 3

      Notice: Undefined index: nm in C:\xampp\htdocs\Mytestsite\api\student_insert.php on line 4

      Notice: Undefined index: rl in C:\xampp\htdocs\Mytestsite\api\student_insert.php on line 5

      Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\Mytestsite\api\student_insert.php on line 12
      {"status":0,"data":"No Record Found"}**

      Any help will be appreciated.
      this is what my code looks like.

      <?php
      $userName=$_POST['username'];
      $Password=$_POST['pass'];
      $Name=$_POST['name'];
      $Rol=$_POST['rol'];
      	
      $conn = mysqli_connect("localhost","root","","bd_mytesttable");
      if ($conn) {
      $obj=array();
      $query= "INSERT INTO tbl_user(username,password,name,rol)VALUES('$userName','$Password','$Name','$Rol')";
      $query_result=mysqli_query($conn,$query);
      if (mysqli_num_rows($query_result)>0) {
       	$row = mysqli_fetch_assoc($query_result);
       		array_push($obj, array(
       		"id" =>$row['id'] ,
       		"username" =>$row['username'] ,
       		"password" =>$row['password'] ,
       		"name" =>$row['name'] ,
       		"rol" =>$row['rol'],  ));
       		echo json_encode(array("status"=>1, "data"=>$obj));	
      }
      else
      {
      echo json_encode(array("status"=>0, "data"=>"No Record Found"));
      }
      //  else
      // {
      // 	echo "No connection";
      }
      ?>
       

      [Mod: Added [code]...[/code] tags]