简体   繁体   中英

My Mysql query is not comparing values

I have this piece of code that I wrote

$stmt = $mysqli->prepare("INSERT INTO `verifyAccounts` (`CUsername`, `CPassword`) VALUES (?,?)");
$stmt->bind_param("ss", $CUsername, $CPassword);
$stmt->execute();
$stmt = $mysqli->prepare("SELECT `Started` FROM `verifyAccounts` WHERE `CUsername` = ?");
do {
    $stmt->bind_param("s", $CUsername);
    $stmt->execute();
    $stmt->bind_result($Startedvalue);
    echo $Startedvalue;
    sleep(2);
} while ($Startedvalue < 2);

if ($Startedvalue == 2) {
    echo "Correct";
} elseif ($Startedvalue == 3) {
    echo "Incorrect";
}
$stmt = $mysqli->prepare("DELETE FROM `verifyAccounts` WHERE `CUsername` = ?");
$stmt->bind_param("s", $CUsername);
$stmt->execute();

For some reason, this doesn't seem to be working, I never get an echo back saying Correct or Incorrect and the account isn't deleted either. It seems like it's stuck in the Do While loop, but $Startedvalue is never echoed either.

Here is the Ajax I have

 function verifyAccount(f) {
            f.preventDefault();
            var CUsername = $('#CUsername').val();
            var CPassword = $('#CPassword').val();
            $.ajax({
                type: 'POST',
                data: {
                    CUsername: CUsername,
                    CPassword: CPassword
                },
                url: 'verifyAccount.php',
                success: function(data) {
                    console.log(data);
                    if (data == "Correct") {
                        $("#verifyPasswordText").text('Valid Login');
                    } else if (data == "Incorrect") {
                        $("#verifyPasswordText").text('Invalid Login');
                        $("#verifyPasswordOKC").prop("disabled", false);
                    } else if (data == "CUsername") {
                        $("#verifyPasswordText").text('Fill out your OKC Username');
                        $("#verifyPasswordOKC").prop("disabled", false);
                    } else if (data == "CPassword") {
                        $("#verifyPasswordText").text('Fill out your OKC Password');
                        $("#verifyPasswordOKC").prop("disabled", false);
                    }           
                },
                error: function(xhr, err) {
                    console.log("readyState: " + xhr.readyState + "\nstatus: " + xhr.status);
                    console.log("responseText: " + xhr.responseText);
                }
            });
        }

Honnestly dont know if it is a good idea to process login this way but

If nothing modifies 'Started', nothing in the code you presented would, then you will be stuck in the do..while

As for the absence of echoes

  1. Makes sure the content type is set before outputting header( 'Content-type: text/html; charset=utf-8' );
  2. flush after each echo flush(); ob_flush(); flush(); ob_flush();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM