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]

    The first batch of error messages would happen if you don't load this page as the result of a form POST, or if you do but the required fields (username, etc.) aren't supplied.

    The MySQL error you're getting would be because you're running an INSERT statement, which doesn't return any rows, just a boolean to say whether or not it succeeded. Did you miss a couple of steps there? (While you're looking at the database code, read up about "SQL injection" and ways to mitigate the hazard.

    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.

      Weedpacket the required fields (username, etc.) aren't supplied.

      As weedpacket pointed out, your form is not providing the information you want to insert in your form. If this line of code:

      $userName=$_POST['username'];

      Is giving you this error:

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

      Then you need to check your input form and make sure your form has method="post" and also make sure that you have an input with name="username" like this:

      <form method="post" action="student_insert.php">
        <input type="text" name="username">
        <input type="password" name="pass">
        <input type="text" name="name">
        <input type="text" name="rol">
          <button>SUBMIT</button>
      </form>
        Write a Reply...