I recently inherited a project at work and I'm trying to set up a local instance on my localhost so I can work with it and not affect the live site. The problem is that some of the ajax calls are giving me errors on response. id is a user id and in the working instance this returns any row in the permissions table that has an id matching the one in the users table. This is only an issue on localhost. Any advice on why this is happening appreciated. Thanks.
Ajax call
$.ajax({
type: 'POST',
url: '../wwwroot/models/apm/CheckAdmin.php',
data: {
eid: id
},
dataType: 'json',
success: function (data) {
//console.log(data);
if (data[0].status == 2) {
ret = true;
$('#devTimeGrp').show();
$('#mngTab').show();
console.log("anAdmin............");
}
else {
ret = false;
$('#devTimeGrp').show();
$('#mngTab').hide();
console.log("notAdmin......");
//$('#mngTab').show();
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
}
});
PHP
<?php
include("../db-settings.php");
$eid = $_POST['eid'];
echo $eid;
$sql="call CheckAdmin('$eid')";
$result = $mysqli->prepare($sql);
$result->execute();
$result->bind_result($col1, $col2, $col3);
while($result->fetch()){
$out[] = array( 'id' => $col1,
'user' => $col2,
'status' => $col3);
}
echo json_encode($out);
$result->close();
?>
Stored procedure
CREATE DEFINER=`myDB`@`%` PROCEDURE `CheckAdmin`(IN p_eid CHAR(36))
BEGIN
SELECT * FROM user_permission WHERE (SELECT id FROM users WHERE uid = p_eid) = user_id;
END
Error
Warning: mysqli_stmt::bind_result(): Number of bind variables doesn't match number of fields in prepared statement
bind_resultfunction, you're trying to bind more variables than what actually is returnedbind_paramwhen making the query, instead of doing variable substitution in the SQL.