3

I am currently experiencing issues with the following script. Upon execution of the script, I do recieve the message "Connection was OK!" however, then I also receive the following messages:

Warning: mysql_query() expects parameter 2 to be resource, object given in /opt/lampp/htdocs/worldofclucky.net/scripts/auth.php on line 11

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /opt/lampp/htdocs/worldofclucky.net/scripts/auth.php on line 12

Any idea what I am doing wrong? I am far from a PHP/MySQL expert, I wouldn't really even consider my self a novice... I did do some testing and the $username variable is sending from the previous page correctly and when typing SELECT * FROM forum.mybb_users WHERE username = 'x_clucky' LIMIT 1 into the MySQL client, it gives all of the information you would expect to get. The PHP code is as follows:

<?php
$username=$_POST["username"];
$hashed_password = md5($_POST['password']); /* For MyBB its $mybb->input['password'] */
$con=mysqli_connect("worldofclucky.net","clucky","CENSORED","forum");

// Check connection
if (mysqli_connect_errno($con))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  } else { echo "Connection was OK!\n";}
$query = mysql_query("SELECT * FROM mybb_users WHERE `username` = '$username' LIMIT 1",$con);
$row = mysql_fetch_array($query);

$encrypted_password = md5(md5($row['salt']).$hashed_password);
if($encrypted_password == $row['password']) {
echo "<script>alert('test');</script>";
}
mysqli_close($con);
?>

Thank you in advanced for your help

Clucky
  • 371
  • 2
  • 4
  • 15
  • Does this answer your question? [Can I mix MySQL APIs in PHP?](https://stackoverflow.com/questions/17498216/can-i-mix-mysql-apis-in-php) – Dharman Feb 23 '20 at 21:48

2 Answers2

9

change mysql to mysqli and use below kind of query. You can't use mysql and mysqli altogether.

$query = mysqli_query($con, "SELECT * FROM mybb_users WHERE `username` = '$username' LIMIT 1");
$row = mysqli_fetch_array($query);
Yogesh Suthar
  • 30,424
  • 18
  • 72
  • 100
3

From a quick look it seems like you are using mysqli functions to connect and then mysql functions to make the actual query. mysql_* functions are now deprecated.

Sabeen Malik
  • 10,816
  • 4
  • 33
  • 50