setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { echo $e; echo json_encode('Error connecting to the server.'); die (); } $sth = $pdo->prepare("SELECT * FROM [BIMComponents].[dbo].[User_Account] WHERE [account] = ?;"); $sth->execute(array($_POST['username'])); if (!isset($_POST['username'], $_POST['password'])) { exit('Please fill both the username and password fields!'); } $i = 0; $query = $sth->fetchAll(); foreach ($query as $row){ $i++; if (md5($_POST['password']) == $row["userPassword"]) { session_regenerate_id(); $_SESSION['loggedin'] = TRUE; $_SESSION['name'] = $row["account"]; $_SESSION['id'] = $row["userID"]; $_SESSION['check_word'] = ''; echo 'success'; } else { echo '密碼錯誤,請重新輸入'; } } if ($i == 0) { echo '帳號不存在,請再次檢查'; } $sth = null; $pdo = null;