Hello seniors,
How are you?
Well I need you help I am new student of php.
Now I am trying to make user login system so that user can login through their password and user name.
But I’m receiving this error.

Fatal error: Cannot redeclare loggedin() (previously declared in C:\xampp\htdocs\series\firstfile\DB\Logging the User In Part\core.inc.php:7) inC:\xampp\htdocs\series\firstfile\DB\Logging the User In Part\core.inc.php on line 12

Below is whole code:

This is index.php page containing code:

require 'core.inc.php';
require 'connect.inc.php';
echo 'you are login.';
include 'loginform.inc.php';

this is connect.inc.php containing code to connect with database

$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_pass = '';

$mysql_db = 'a_database';

if(!mysql_connect($mysql_host, $mysql_user, $mysql_pass) || ! mysql_select_db($mysql_db))     {

core.inc.php page, I think this is creating problem if this not the index.php

$current_file = $_SERVER;

function loggedin(){
if(isset($_SESSION) && !empty($_SESSION)){
return true;
return false;

last one page is loginform.inc.php which will check weather user have enter something or not after that check username and password is correct or not?

require 'core.inc.php';

if(isset($_POST) && isset($_POST)){
$password_hash = md5($password);

if(!empty($username) && ! empty($password)){
$query = "SELECT id FROM users WHERE username = '$username' AND password = '$password_hash'";
if($query_run = mysql_query($query)){
$query_num_rows = mysql_num_rows($query_run);
echo 'Invalid';
}else if($query_num_rows ==1){
$user_id = mysql_result($query_run, 0, 'id');
echo $user_id;
header('Location: main.php');
echo 'You must enter a username and password.';
<form action="<?php echo $current_file; ?>" method="POST">
Usrename: <input type="text" name="username">
Password: <input type="password" name="password">
<input type="submit" value="Log in">

and db is containing these things

id  username    password                 firstname   surname
1   alex    32250170a0dca92d53ec9624f336ca24    Alex    Garrett

Now please help me out why is this script is returning error and how this problem will be solve.

Recommended Answers

All 2 Replies

remove this line from loginform.inc, you have already included core.inc.php.

require 'core.inc.php';

or use


O thank you so much dear urtrivedi for my help.
this was my first experience to posted and share problem here.
but was a great experience
thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.