note 120089 deleted from mysqli.real-query by cmb

From: Date: Sun, 10 Feb 2019 11:31:56 +0000
Subject: note 120089 deleted from mysqli.real-query by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-210222@lists.php.net to get a copy of this message
Note Submitter: Tinker ---- Straightforward function - simply connect to the database and execute a query, similar to this function bellow. <?php function check_password($username, $password) { // Create connection $db = new mysqli('localhost','database_user','database_pass','database_name'); // Check for errors if($db->connect_errno){ echo $db->connect_error; } // Execute query $result = $db->real_query("Select * From users Where username='$username' And password='$password'"); // Always check for errors if($db->connect_errno){ echo $db->connect_error; } return $result == true; } ?> Very easy. Replace database_user, database_pass and database_name with the proper names, and the text inside real_query with your actual query. Don't forget the quotes on either side (except for numbers, there you can omit them) otherwise it won't work. Hope that helps someone.

« previous php.notes (#210222) next »