MySQL mysqli Writer #1, 2010-06-15 mysqli is a built in part of mysql 4.1. It incorporates all functionality required to interact with a database from your PHP file. It has basics like querying the database, which includes SELECTing data as well as INSERTing data. It also give the ability to use prepared statements, transactions which can be committed or rolled back. General Use Generally speaking you can fulfill your needs using the basics of inserting, querying, updating, and deleting. Mysqli requires a connection object and a query to work. Connection Object $db_ip = '127.0.0.1'; $db_username = 'adminguy'; $db_pw = 'supersecret'; $db_name = 'mydb'; $conn = mysqli_connect('$db_ip', '$db_username', '$db_pw', '$db_name'); // Now $conn is your connection object. Query // First, make sure the POSTs exist so you don't blow up the page if(isset($_POST['username']) && $_POST['username'] != '' && isset($_POST['password']) && $_POST['password'] != ''){ // next set the POST array variable to a // local variable for easier querying. // Also, encrypt the password using SHA1, if your database // was set up for it. $username = $_POST['username']; $password = SHA1($_POST['password']); $sql = "SELECT COUNT(*) count FROM myTable WHERE username = '$username' AND password = '$password'"; } Putting it Together You have both required parts for your query. Now, execute. To keep your code to a minimum with maximum functionality, it is recommended that you take advantage of the fact that mysqli queries return false if they fail. So, execute your query in an “if” statement so it automatically continues if it works. $login_success = false; if($results = mysqli_query($conn, $sql)){ // loop through the results while($row = mysqli_fetch_array($results)){ $count = $row['count']; if($count == 1){ $login_success = true; } } } if($login_success){ echo "You are logged in."; } Programming SQL mysqlmysqlisql