1

Here is the code that is giving me the Warning

$query = mysqli_query($connection, $sql);
$uname_check = mysqli_num_rows($query);

What is the problem here ? Similar code elsewhere in the page is working.

Also, I am getting the following error in the next line of code:

mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in ~\index.php on line 47
Shreyas Tripathy
  • 325
  • 7
  • 19

1 Answers1

1

You're mixing MySQL API's (mysql_* and mysqli_*)

You have to use something like this:

$con = mysqli_connect("localhost","root","") or die ("could not connect");

And to select your database (mysqli_select_db):

mysqli_select_db("s3f") or die ("no database");   

Also for your connection error handling use (mysqli_connect_error()):

mysqli_connect_error()

Side note:

If you're in a testing environment i would recommend you to put error reporting at the top of your file(s):

<?php
    ini_set("display_errors", 1);
    error_reporting(E_ALL);
?> 
Rizier123
  • 58,877
  • 16
  • 101
  • 156
  • Hi. Thanks that worked ... but it is still giving me an error saying it requires 2 parameters. So I added the connection as the second parameter as suggested on www.php.net Now the same error of **mysqli** is back Also ... Database Selection Failed ! – Shreyas Tripathy Dec 19 '14 at 12:01
  • @ShreyasTripathy Look carefully! When you're programming procedural (what you're doing) then the connection comes first and then the query! See: http://php.net/manual/en/mysqli.query.php – Rizier123 Dec 19 '14 at 12:06
  • @ShreyasTripathy You're welcome! (BTW: I would recommend you to search next time a little bit more! ;D e.g. this question was asked so many times before and there are so many solutions!) – Rizier123 Dec 19 '14 at 12:12
  • Will do ! I have this project to submit I was quite frustrated – Shreyas Tripathy Dec 19 '14 at 12:22