In my PHP application, I want the user to be able to login with email, username and number recorded in the database. Yet, I
init.php
<?php $server = 'localhost'; $username = 'default'; $password = 'xxxx'; $database = 'default'; try{ $conn = new PDO("mysql:host=$server;dbname=$database;", $username, $password); } catch(PDOException $e){ die( "Connection failed: " . $e->getMessage()); } login.php
<?php session_start(); if(isset($_SESSION['user_name'])!='') { header('Location: index.php'); } include_once 'init.php'; //check if form is submitted if (isset($_POST['login'])) { $email = $_POST['email']; $password = $_POST['password']; $records = $conn->prepare('SELECT username,email,number,password FROM users WHERE username = :login OR email = :login OR number = :login'); $records->bindParam(':login', $email); $records->execute(); $results = $records->fetch(PDO::FETCH_ASSOC); $message = ''; if(count($results) > 0 && password_verify($password, $results['password']) ){ $gome = $results['username'];$_SESSION['user_name'] = $gome; $CookieExpire = 1000; $time = 100 * 70 * 48 * 86400; $time = time() + $time; setcookie('username', '$gome', '$time'); setcookie('password', '$password', '$time');header("Location: /"); } else { $message = 'Sorry, those credentials do not match'; } } ?> In returns i get this error: Fatal error: Call to a member function prepare() on a non-object in /var/www/u0377863/public_html/xx.com/dom/login.php on line 11:
$records = $conn->prepare('SELECT username,email,number,password FROM users WHERE username = :login OR email = :login OR number = :login');