1

I'm getting the following two errors when I run the below code in my browser, the code itself seems to work as I can login and register and add to the database but still the errors persist. Php Error:

The code is:

<?php 
   require "conn.php";
   $doctor_number = $_POST["doctor_number"];
   $doctor_name = $_POST["doctor_name"];
   $email = $_POST["email"];
   $password = $_POST["password"];
   $mysql_qry = "insert into doctors(doctor_number, doctor_name, email, password) values ('$doctor_number', '$doctor_name', '$email', '$password')";
   $result = mysqli_query($conn ,$mysql_qry);
   if($conn->query($mysql_qry) === TRUE){
       echo "Insert Successful";
   }
   else{
       echo "Error: " . $mysql_qry . "<br>" . $conn->error;
   }
   $conn->close();

?>

Php errors

<?PHP
   require "conn.php";
   $email = $_POST["email"];
   $password = $_POST["password"];
   $mysql_qry = "select * from doctors where email like '$email' and password like '$password'";
   $result = mysqli_query($conn ,$mysql_qry);
   if(mysqli_num_rows($result) > 0){
       echo "Login success";
   }
   else{
       echo "Login not successful";
   }

?>

  • The Content of $_POST only exists once after a form (method=Post) has been submitted. In fact it is not a database-error... – Oliver Mar 06 '17 at 12:06
  • I'm not great at PHP, could you suggest how I'd fix it? –  Mar 06 '17 at 12:07
  • This is not PHP related. It is a normal behavior of all Languages. Just put your Login-credentials into a $_SESSION and keep you logged in. But avoid sending login-credentials to the database on every request – Oliver Mar 06 '17 at 12:12
  • Okay thanks, I'm going to close the question as it appears to be a duplicate –  Mar 06 '17 at 12:15

1 Answers1

0

Put the below code in if isset condition

<?php 
require "conn.php";
if(isset($_POST)){
    $doctor_number = $_POST["doctor_number"];
    $doctor_name = $_POST["doctor_name"];
    $email = $_POST["email"];
    $password = $_POST["password"];
    $mysql_qry = "insert into doctors(doctor_number, doctor_name, email, password) values ('$doctor_number', '$doctor_name', '$email', '$password')";
    $result = mysqli_query($conn ,$mysql_qry);
    if($conn->query($mysql_qry) === TRUE){
        echo "Insert Successful";
    }
    else{
        echo "Error: " . $mysql_qry . "<br>" . $conn->error;
    }
    $conn->close();
}?>
Rushil K. Pachchigar
  • 1,263
  • 2
  • 21
  • 40