How to resolve PHP error messages? Although I tried, still no success.
P粉773659687
2023-08-08 12:34:18
<p><br /></p>
<pre class="brush:php;toolbar:false;">function confirmUserID($session_id, $userid) {
/* Verify that user is in database */
$query = "SELECT session_id FROM user_sessions WHERE session_id = '$session_id' AND userid = '$userid'";
$stmt = $this->db->prepare($query);
$stmt->execute(array(':userid' => $userid, ':sessionid' => $session_id)); // Error message indicates it is coming from here
$count = $stmt->rowCount();
if (!$stmt || $count < 1) {
return 1; // Indicates username failure
}
$dbarray = $stmt->fetch();
/* Validate that userid is correct */
if ($session_id == $dbarray['session_id']) {
return 0; // Success! Username and userid confirmed
} else {
return 2; // Indicates userid invalid
}
}</pre>
<p>我一直收到这个错误信息。</p>
<blockquote>
<p>Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:xampphtdocstintoadminincludesSession.php:129 Stack trace: #0 C:xampphtdocstintoadminincludesSession.php(129): PDOStatement->execute(Array) #1</p>
</blockquote>
<pre class="brush:php;toolbar:false;">function confirmUserID($session_id, $userid) {
/* Verify that user is in database */
$query = "SELECT session_id FROM user_sessions WHERE session_id = '$session_id' AND userid = '$userid'";
$stmt = $this->db->prepare($query);
$stmt = array(':userid' => $userid, ':sessionid' => $session_id); // Error message indicates it is coming from here
$stmt->execute();
$count = $stmt->rowCount();
if (!$stmt || $count < 1) {
return 1; // Indicates username failure
}
$dbarray = $stmt->fetch();
/* Validate that userid is correct */
if ($session_id == $dbarray['session_id']) {
return 0; // Success! Username and userid confirmed
} else {
return 2; // Indicates userid invalid
}
}</pre>
<p>给出了更多的错误提示</p>
You should add a colon (:) before the placeholder and avoid concatenating the $userID and $sessionID variables with the query.