when i run the register.php code form not show in browser
this is my whole code..
class.php
include ("config.php");
class User{
public $db;
public function __construct()
{
$this->db = new mysqli('localhost', 'root', 'iws123#', 'register');
if(mysqli_connect_errno())
{
echo "Error: Could not connect to database.";
exit;
}
}
/*** for registration process ***/
public function reg_user($first_name,$last_name,$username,$email,$password,$type)
{
$sql="SELECT * FROM user_table2 WHERE username='$username'";
//checking if the username is available in db
$check = $this->db->query($sql) ;
$count_row = $check->num_rows;
//if the username is not in db then insert to the table
if ($count_row == 0)
{
$sql1="INSERT INTO user_table2 SET first_name='".$first_name."',last_name ='".$last_name."', username='".$username."',email='".$email."',password='".$password."',type='".$type."'";
$result = mysqli_query($this->db,$sql1) or die(mysqli_connect_errno()."Data cannot inserted");
return $result;
}
else
{
return false;
}
}
/*** for login process ***/
public function check_login($username, $password){
$sql2="SELECT id from user_table2 WHERE username='$username' and password='$password'";
//checking if the username is available in the table
$result = mysqli_query($this->db,$sql2);
$user_data = mysqli_fetch_array($result);
$count_row = $result->num_rows;
if ($count_row == 1) {
// this login var will use for the session thing
$_SESSION['login'] = true;
$_SESSION['id'] = $user_data['id'];
return true;
}
else{
return false;
}
}
/*** starting the session ***/
public function get_session()
{
return $_SESSION['login'];
}
public function user_logout() {
$_SESSION['login'] = FALSE;
session_destroy();
}
}
?>
class User{
public $db;
public function __construct()
{
$this->db = new mysqli('localhost', 'root', 'iws123#', 'register');
if(mysqli_connect_errno())
{
echo "Error: Could not connect to database.";
exit;
}
}
/*** for registration process ***/
public function reg_user($first_name,$last_name,$username,$email,$password,$type)
{
$sql="SELECT * FROM user_table2 WHERE username='$username'";
//checking if the username is available in db
$check = $this->db->query($sql) ;
$count_row = $check->num_rows;
//if the username is not in db then insert to the table
if ($count_row == 0)
{
$sql1="INSERT INTO user_table2 SET first_name='".$first_name."',last_name ='".$last_name."', username='".$username."',email='".$email."',password='".$password."',type='".$type."'";
$result = mysqli_query($this->db,$sql1) or die(mysqli_connect_errno()."Data cannot inserted");
return $result;
}
else
{
return false;
}
}
/*** for login process ***/
public function check_login($username, $password){
$sql2="SELECT id from user_table2 WHERE username='$username' and password='$password'";
//checking if the username is available in the table
$result = mysqli_query($this->db,$sql2);
$user_data = mysqli_fetch_array($result);
$count_row = $result->num_rows;
if ($count_row == 1) {
// this login var will use for the session thing
$_SESSION['login'] = true;
$_SESSION['id'] = $user_data['id'];
return true;
}
else{
return false;
}
}
/*** starting the session ***/
public function get_session()
{
return $_SESSION['login'];
}
public function user_logout() {
$_SESSION['login'] = FALSE;
session_destroy();
}
}
?>
register.php
include ("class.php");
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$user = new User(); // Checking for user logged in or not
if (isset($_REQUEST['submit']))
{
//extract($_REQUEST);
$register = $user->reg_user($first_name,$last_name $username,$email,$password,$type );
if ($register)
{
echo 'Registration successful Click here to login';
}
else
{
echo 'Registration failed.Username already exits';
}
}
?>
login.php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$user = new User(); // Checking for user logged in or not
if (isset($_REQUEST['submit']))
{
//extract($_REQUEST);
$register = $user->reg_user($first_name,$last_name $username,$email,$password,$type );
if ($register)
{
echo 'Registration successful Click here to login';
}
else
{
echo 'Registration failed.Username already exits';
}
}
?>
Registration Here
login.php
session_start();
include ("class.php");
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$user = new User();
if (isset($_REQUEST['submit'])) {
//extract($_REQUEST);
$login = $user->check_login($username, $password);
if ($login)
{
// Registration Success
header("location:home.php");
}
else {
// Registration Failed
echo 'Wrong username or password';
}
}
?>
home.php
include ("class.php");
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$user = new User();
if (isset($_REQUEST['submit'])) {
//extract($_REQUEST);
$login = $user->check_login($username, $password);
if ($login)
{
// Registration Success
header("location:home.php");
}
else {
// Registration Failed
echo 'Wrong username or password';
}
}
?>
Login Here
home.php
session_start();
include ('class.php');
$user = new User();
$id = $_SESSION['id'];
if (!$user->get_session())
{
header("location:login.php");
}
if (isset($_GET['q']))
{
$user->user_logout();
header("location:login.php");
}
?>
Home
include ('class.php');
$user = new User();
$id = $_SESSION['id'];
if (!$user->get_session())
{
header("location:login.php");
}
if (isset($_GET['q']))
{
$user->user_logout();
header("location:login.php");
}
?>
Home

Manikandan MurugesanPosted Jun 11, 2017, 12:16 AM