各位新人大家好,我試圖弄清楚為什么我的代碼在我的 $loginresult 不 = 1 時(shí)返回“登錄成功”。這是我第一次嘗試使用我的登錄系統(tǒng)實(shí)現(xiàn)準(zhǔn)備好的語(yǔ)句以避免 SQL 注入,并且很好奇是否問(wèn)題在于我是如何寫的。我可以肯定地說(shuō),當(dāng)我成功登錄時(shí),我的值為 1,不成功則為 5。每當(dāng)它是 5 時(shí),它仍然返回與 1 應(yīng)該返回的相同的回顯。感謝大家的時(shí)間和耐心。<?php session_start(); ?><!DOCTYPE html><head> <title>Login</title></head><body><?phpinclude('config.php');$conn = sqlsrv_connect($serverName, $conn_array); $myparams['username'] = $_POST['username']; $myparams['password'] = $_POST['password']; // All checks done already (including password check). Begin building prepare statement. $sql = "SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON SET CONCAT_NULL_YIELDS_NULL ON SET ANSI_WARNINGS ON SET ANSI_PADDING ON exec LoginScript @in_accountname=?,@in_password=? ";//Array for prep$procedure_params = array( array(&$myparams['username'], SQLSRV_PARAM_IN), array(&$myparams['password'], SQLSRV_PARAM_IN));/* Prepare the statement. */if( $stmt = sqlsrv_prepare( $conn, $sql, $procedure_params)){ // echo "Statement was successfully prepared.\n";} else{ echo "Statement could not be prepared.\n"; // ( print_r( sqlsrv_errors(), true)); ACTIVATE ONLY FOR DEBUGGING TO PREVENT HELPING SQL INJECTORS}/* Execute the statement. */if( sqlsrv_execute( $stmt)){ // echo " Statement executed.\n";}else{ echo " Unable to execute prepared statement!\n"; // ( print_r( sqlsrv_errors(), true));}//checkuser$result = sqlsrv_prepare( $conn, $sql, $procedure_params);$info=sqlsrv_fetch_array($stmt);$LoginResult = $info;//Login Successif (!$LoginResult=1){ echo "Login DEAD."; echo "Login Result: ".$info[0]."\n"; }else{ echo "Login Successful."; echo "Login Result: ".$info[0]."\n"; }/* Free the statement and connection resources. */sqlsrv_free_stmt($stmt);sqlsrv_close($conn);?>```
PHP+SQL登錄系統(tǒng)。返回錯(cuò)誤的值
寶慕林4294392
2023-07-01 17:38:22