Clucky Clucky - 1 year ago 220
MySQL Question

Warning: mysql_query() expects parameter 2 to be resource

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/ on line

Warning: mysql_fetch_array() expects parameter 1 to be resource, null
given in /opt/lampp/htdocs/ on line

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:

$hashed_password = md5($_POST['password']); /* For MyBB its $mybb->input['password'] */

// 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>";

Thank you in advanced for your help

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download