Search code examples
phpmysqlvalidationserver-side

PHP Server-Side Validation of Related Fields


I have a user table with userid and password. I would like all form submissions to be 'verified' by another user by entering userid and password before submission. I have a code that works to verify the userid, but I would like to also verify the password, but obviously linked to the userid. This is NOT a login form, all it does is verify that a users entered userid and password are correct.

The 'verify' fields in my form are called: userid_ver and password_ver.

Any help is very appreciated! Thank you.

    $rs = CustomQuery("select userid from user where userid = '"
. db_addslashes($values["userid_ver"]) . "'");
if (db_fetch_array($rs)==false)
{
$message = "UserID is incorrect. Please try again.";
return false;
}
$message="";
return true;

Solution

  • I think you made a mistake should be userid_ver = '...

    Anyway if you are asking just to add a checking in your query, then add this at the end of your sql statement, just be sure that the $values["password_ver"] is set:

    ." AND password_ver = '". db_addslashes($values["password_ver"]) . "'"
    

    Complete:

    $rs = CustomQuery("select userid from user where userid = '"
    . db_addslashes($values["userid_ver"]) . "' AND password_ver = '". db_addslashes($values["password_ver"]) . "'");
    if (db_fetch_array($rs)==false)
    {
    $message = "UserID is incorrect. Please try again.";
    return false;
    }
    $message="";
    return true;