How to add email?


<?php		
	session_start();
    if(isset($_SESSION['user']) && $_SESSION['user']!=''){
    header("Location: home.php");
    } 
	
    if($_SERVER['REQUEST_METHOD']=='POST' && isset( $_POST['submit'])){
        include("script/dbconnect.php");
		$username = stripslashes($_POST['username']);
		$password = stripslashes($_POST['password']);
		$username = mysqli_real_escape_string($conn, $username);
		$password = mysqli_real_escape_string($conn, $password);		
		$stmt = $conn->prepare("SELECT userid FROM maintable  WHERE username=? and userpass=?");
		$stmt->bind_param("ss", $username,$password);
		$stmt->execute();		
		$stmt->bind_result($id);		
		if($stmt->fetch()){
		$_SESSION['user']=$id;
		header("Location: home.php");
		}else{
			  $stmt->close();
		      $conn->close();
			  echo "<script>
						alert('u are not an admin !!!');
						window.location.href='index.php';
					</script>";
		}					 
		$stmt->close();
		$conn->close();			
	}
?>

Add email where, for what ? I don’t see any question here only code snippet.

1 Like

want to add email in my login page.

Hi rubelahmedvu welcome to the forum

There are three areas you’ll need to look at

  • the login form will need to have an email address input
  • the database will need to have a field to hold the email addresses
  • the PHP code will need to have lines added to process the POST values and the query modified to use the email address field

To user can login with username or email ?

how to add email verification?

can u give me the code?

$username = stripslashes($_POST['username']);
$password = stripslashes($_POST['password']);
$email = stripslashes($_POST['email']);
$username = mysqli_real_escape_string($conn, $username);
$password = mysqli_real_escape_string($conn, $password);
$email = mysqli_real_escape_string($conn, $email);		
$stmt = $conn->prepare("SELECT userid, username, userpass, email FROM maintable  WHERE username=? OR email=? and userpass=?");
$stmt->bind_param("sss", $username,$password,$email);

And add in your login form field <input type="email" name="email">

EDIT : added Select fields from database.

And run this to add email field in your table

ALTER TABLE maintable
ADD email varchar(255) NOT NULL;

Insert value

INSERT INTO maintable (userid, username, userpass, email) VALUES
(11, 'rubel', 'rubel', 'test@mail.com');

CREATE TABLE maintable (
userid int(10) NOT NULL,
username varchar(30) NOT NULL,
userpass varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


– Dumping data for table maintable

INSERT INTO maintable (userid, username, userpass) VALUES
(11, ‘rubel’, ‘rubel’);

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.