Tom10 Posted May 7, 2015 Share Posted May 7, 2015 <?php @ini_set('display_errors', 1); @error_reporting(1); @ini_set('allow_url_include', Off); @set_time_limit(0); require 'connect.php'; if($_SERVER['REQUEST_METHOD'] == "POST") { $username = $_POST['username']; $password = $_POST['password']; $username = htmlspecialchars($username); $username = htmlentities($username); $username = strip_tags($username); if(preg_match("#[^\w]#", $username)) { die("Your username must be numbers or letters only!"); } $hash = hash('ripemd320', $password); if(empty($username) || empty($password)) { die("Please enter both your username and password!"); } $sql = "SELECT username, password FROM users WHERE BINARY username = :username AND BINARY password = :password"; $stmt = $handler->prepare($sql); $stmt->bind_param("ss", $username, $hash); $stmt->execute(); if($stmt->rowCount()) { if($row['rank'] == 1) { $_SESSION['loggedIn'] = 1; $_SESSION['username'] = $username; $_SESSION['rank'] = $row['rank']; echo '<meta http-equiv="refresh" content="0;admin.php">'; } $_SESSION['loggedIn'] = 1; $_SESSION['username'] = $username; $_SESSION['rank'] = $row['rank']; echo '<meta http-equiv="refresh" content="0;user.php">'; } } ?> I'm getting the following error Call to undefined method PDOStatement::bind_param() Link to comment https://forums.phpfreaks.com/topic/296138-call-to-undefined-method-pdostatementbind_param/ Share on other sites More sharing options...
ginerjm Posted May 7, 2015 Share Posted May 7, 2015 Did you connect to your database and assign $stmt? You don't check any results so you can't be sure, can you? Link to comment https://forums.phpfreaks.com/topic/296138-call-to-undefined-method-pdostatementbind_param/#findComment-1511054 Share on other sites More sharing options...
Tom10 Posted May 7, 2015 Author Share Posted May 7, 2015 Did you connect to your database and assign $stmt? You don't check any results so you can't be sure, can you? I have required the connect file and $stmt = $handler->prepare($sql); $stmt->bind_param("ss", $username, $hash); $stmt->execute(); Link to comment https://forums.phpfreaks.com/topic/296138-call-to-undefined-method-pdostatementbind_param/#findComment-1511057 Share on other sites More sharing options...
mac_gyver Posted May 7, 2015 Share Posted May 7, 2015 you are using the PDO statements for your database connection. all of the rest of your database statements must also be PDO statements. the bind_parm() statement you are using is a mysqli statement. you cannot mix the different types of database statements. i recommend that you use the php.net documentation as a reference source to avoid confusion like this. Link to comment https://forums.phpfreaks.com/topic/296138-call-to-undefined-method-pdostatementbind_param/#findComment-1511067 Share on other sites More sharing options...
Tom10 Posted May 7, 2015 Author Share Posted May 7, 2015 ok thanks, and this is my connection script <?php try { $handler = new PDO("mysql:host=localhost;dbname=test;", "root", ""); $handler->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { echo "A connection could not be established to ".$_SERVER['SERVER_ADDR']." The following error has occurred: ".$e->getMessage()." "; } ?> Link to comment https://forums.phpfreaks.com/topic/296138-call-to-undefined-method-pdostatementbind_param/#findComment-1511072 Share on other sites More sharing options...
mac_gyver Posted May 8, 2015 Share Posted May 8, 2015 no one stated there was a problem with your database connection, so i don't know why you posted the above code. the problem is that there is no pdo bind_param() method. to use the PDO database statements correctly, you must read the php.net documentation for what you are doing. just coping things you have have seen someplace, without knowing what they mean and what they do, isn't going to work. Link to comment https://forums.phpfreaks.com/topic/296138-call-to-undefined-method-pdostatementbind_param/#findComment-1511182 Share on other sites More sharing options...
jcbones Posted May 9, 2015 Share Posted May 9, 2015 I believe you are looking for: PDOStatement.bindParam Link to comment https://forums.phpfreaks.com/topic/296138-call-to-undefined-method-pdostatementbind_param/#findComment-1511267 Share on other sites More sharing options...
Tom10 Posted May 10, 2015 Author Share Posted May 10, 2015 #Removed Link to comment https://forums.phpfreaks.com/topic/296138-call-to-undefined-method-pdostatementbind_param/#findComment-1511296 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.