-1

Warning: mysqli_fetch_array() expects parameter 1 to be
mysqli_result, null given in C:\wamp64\www\login1\save.php on line 9
Warning: mysqli_query() expects at least 2 parameters, 1 given in
C:\wamp64\www\login1\save.php on line 8

I am clearly new to php and sql. I tried writing a code for a simple login page.

Save.php:

<?php
     $conn=mysqli_connect('localhost','','');
     if($conn)
     {   
         mysqli_select_db($conn,"studentdb");
         $query="select * from user";
         $result=mysqli_query($query);
         while( $row=mysqli_fetch_array($result) )
         { 
           echo "<br><br> *******USER DATA*********";
           echo "<br> Name : $row[name]";
           echo "<br> Username : $row[username] ";
           echo "<br> Password : $row[password] ";

         }

     }
     mysqli_close($conn);
?>

Next page after login:

<?php

      $name=$_GET['name'];
      $username=$_GET['uname'];
      $password=$_GET['pwd'];
      echo "<h3> Welcome $name...!</h3>";

      $conn=mysql_connect('localhost','root','');
      if($conn)
       { 
         mysql_select_db("studentdb",$conn);
         $query="insert into user values ('$name', '$username', '$password')";
         mysql_query($query);
         echo "Your Login Registration is successful !!!!";

       }
       mysql_close($conn);

?>

This is what I have written. I am getting the above mentioned error while give required information in name, username and password.

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Your code that you've posted isn't using either of the functions issuing warnings. Can you provide complete code, and also format your code so that it's readable? –  Oct 22 '20 at 05:05
  • You shouldn't be using the `mysql_` functions; they have been deprecated in PHP5 and removed in PHP6. – Nick Oct 22 '20 at 05:19
  • Your query failed. Perhaps you have no `user` table in the `studentdb`? – Nick Oct 22 '20 at 05:19

1 Answers1

0

In Save.php file and in database connection, you don't pass SQL username that in localhosts is root

so replace your connection with following:

$conn=mysqli_connect('localhost','root','');

and in query pass $conn variable as first parameter. it's not neccesary but this is better. sample:

$result=mysqli_query($conn, $query);
Dharman
  • 30,962
  • 25
  • 85
  • 135
AmirAli Esteki
  • 542
  • 3
  • 13