I wrote a modify password file, but unfortunately, the MySQL query is throwing error:
Warning: mysql_query() expects at most 2 parameters, 3 given in admin\modify-password.php on line 40
This is the PHP code:
if (mysql_query("UPDATE admin SET hash = ? WHERE admin_id = ?", crypt($_POST["newpassword"]), $_SESSION["admin_id"]) === false)
I modified the code like this, and it produced a different error message:
if (mysql_query("UPDATE admin SET hash = ? WHERE username = 'admin'", '$newpassword') === false)
The second error message:
Warning: mysql_query() expects parameter 2 to be resource, string given in admin\modify-password.php on line 40
Here is the full code:
<?php
// if form was submitted
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
//This gets all the other information from the form
$curpassword = mysql_real_escape_string(crypt($_POST["curpassword"]));
$newpassword = mysql_real_escape_string(crypt($_POST["newpassword"]));
$confirmation = mysql_real_escape_string(crypt($_POST["confirmation"]));
// validate submission
if (empty($_POST["curpassword"]))
{
echo nl2br ("You must provide your current password. \n");
}
if (empty($_POST["newpassword"]))
{
echo nl2br ("You must enter a desired new password. \n");
}
if (empty($_POST["confirmation"]))
{
echo nl2br ("You must confirm your new password. \n");
}
// query database for admin
$rows = mysql_query("SELECT * FROM admin WHERE username = 'admin'");
//$row = $rows[0];
// compare hash of user's input against hash that's in database
if (crypt($_POST["curpassword"], $row["hash"]) != $row["hash"])
{
echo nl2br ("Your input and your current password don't match. \n");
}
if ($_POST["newpassword"] != $_POST["confirmation"])
{
echo nl2br ("Your new password and confirmation don't match. \n");
}
// update the admin's password to the new one
if (mysql_query("UPDATE admin SET hash = ? WHERE admin_id = ?", crypt($_POST["newpassword"]), $_SESSION["admin_id"]) === false)
{
echo "Internal server error occurred.";
}
else
{
// redirect to the logged in admin's profile
//header("Location: index.php");
}
}
?>
Please, note: I'm trying to use MySQL and not MySQLi. I have a plausible reason for doing so at the moment.
Thanks in advance for your continued help.