When I tried to run this function I get:
Fatal error: Uncaught Error: Call to a member function bind_param() on boolean in /var/www/html/include/function/token.php:73 Stack trace: #0 /var/www/html/view.php(14): dirTOperm('/var/www/html/u...') #1 {main} thrown in /var/www/html/include/function/token.php on line 73
The function is as follows:
function dirTOperm($dir){
global $mysql_ip, $mysql_user, $mysql_pass, $mysql_database_name,$_SESSION;
$conn = new mysqli($mysql_ip, $mysql_user, $mysql_pass, $mysql_database_name);
$stmt = $conn->prepare('SELECT * FROM token-perm WHERE directory = ?');
$stmt->bind_param('s', $dir);
$stmt->execute();
$result = $stmt->get_result();
$checktoken = $result->num_rows;
$row = $result->fetch_assoc();
$stmt->close();
$conn->close();
if ($checktoken == 0) {
$permtoken = GenerateRandomString(512);
$conn = new mysqli($mysql_ip, $mysql_user, $mysql_pass, $mysql_database_name);
$stmt = $conn->prepare('INSERT INTO token-perm (token,directory,date) VALUES ("?","?","?")');
$stmt->bind_param('sss', $permtoken,$dir,date('d-m-Y H:m'));
$stmt->execute();
$stmt->close();
$conn->close();
return $permtoken;
}else {
return $row['token'];
}
}
Connection data is correct and trying to search on google I have not risen to solve, can you help me?
prepare(), it might returnfalse, see: php.net/manual/en/mysqli.prepare.php"around the?the prepared statements will pack the variable for you.echo $conn->errorafter the prepare statement to see the error