1

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?

7
  • You need to check the result of prepare(), it might return false, see: php.net/manual/en/mysqli.prepare.php Commented Nov 26, 2017 at 21:27
  • 2
    Using dashes in table names is somewhat ... emm ... gnarly. Commented Nov 26, 2017 at 21:29
  • 1
    Note: you don't need to use quotes " around the ? the prepared statements will pack the variable for you. Commented Nov 26, 2017 at 21:31
  • even without " the problem does not resolve Commented Nov 26, 2017 at 21:48
  • I know, this was just a note not a solution. Anyway do echo $conn->error after the prepare statement to see the error Commented Nov 26, 2017 at 21:56

1 Answer 1

1

never use dashes(-) in table names

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.