Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3316506
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:28:39+00:00 2026-05-17T22:28:39+00:00

i have the process page for login, i can connected to DB and also

  • 0

i have the process page for login, i can connected to DB and also can check the username and password.

but after that, i cant show the index page after login success.This is my code:

$dbc=mysql_connect(_SRV,_ACCID,_PWD) or die(_ERROR15.": ".mysql_error());
$db=mysql_select_db("qdbase",$dbc) or die(_ERROR17.": ".mysql_error());

    switch(postVar('action')) {
                    case 'submitlogin' :
                    submitlogin(postVar('loguser'),postVar('logpass'));
                    break;
    }
    function submitlogin($loguser,$logpass){
    if(isset($loguser, $logpass)) {
        ob_start();
        // To protect MySQL injection (more detail about MySQL injection)
        $myusername = stripslashes($loguser);
        $mypassword = stripslashes($logpass);
        $myusername = mysql_real_escape_string($myusername,$dbc);
        $mypassword = mysql_real_escape_string($mypassword, $dbc);
        $sql="SELECT * FROM admin WHERE user='$myusername' AND password=('$mypassword')";
        $result=mysql_query($sql, $dbc);
        // Mysql_num_row is counting table row
        $count=mysql_num_rows($result);
        // If result matched $myusername and $mypassword, table row must be 1 row
        if($count==1){
            // Register $myusername, $mypassword and redirect to file "admin.php"
            session_register("admin");
            session_register("password");
            $_SESSION['name']= $myusername;
            header("location:index1.php");
        }
        else {
            $msg = "Wrong Username or Password. Please retry";
            header("location:login.php?msg=$msg");
        }
  //      ob_end_flush();
    }
    else {
        header("location:login.php?msg=Please enter some username and password");
    }
    mysql_close($dbc);
    ob_end_flush();
    }

can you help me to resolve this problem?


EDIT

i get confusing in this part from index1.php:

<?php
session_start(); //Start the session
define(ADMIN,$_SESSION['name']); //Get the user name from the previously registered super global variable
if(!session_is_registered("admin")){ //If session not registered
header("location:login.php"); // Redirect to login.php page
}
else //Continue to current page
header( 'Content-Type: text/html; charset=utf-8' );
?>

and this part from login.php, because i think they unsyncronize:

if(mysql_num_rows($result) > 0)
        {
            session_register("admin");
            session_register("password");

            $_SESSION['name']= $myusername;

            header("location:index1.php");
        }

i’m just have user and password, where is the admin come from? bcoz from this i get:

 PHP Notice:  Use of undefined constant ADMIN - assumed 'ADMIN' in /var/www/html/index1.php on line 12
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:28:39+00:00Added an answer on May 17, 2026 at 10:28 pm

    Your messing up your real escapes.

    $myusername = mysql_real_escape_string($dbc, $myusername);
    $mypassword = mysql_real_escape_string($dbc, $mypassword);
    

    Should be

    $myusername = mysql_real_escape_string($myusername, $dbc);
    $mypassword = mysql_real_escape_string($mypassword, $dbc);
    

    heres the doc block:

    string mysql_real_escape_string ( string $unescaped_string [, resource $link_identifier ] )
    

    @source: http://php.net/manual/en/function.mysql-real-escape-string.php

    And

    $result=mysql_query($dbc, $sql);
    

    Should Be

    $result = mysql_query($sql, $dbc);
    

    Update #1

    Not promising this will work be just gone threw your code and cleaned it up, removed some stuff and added some stuff:

    if(false === ($dbc = mysql_connect(_SRV,_ACCID,_PWD) die(_ERROR15.": ".mysql_error());
    if(false === mysql_select_db("qdbase",$dbc)) die(_ERROR17.": ".mysql_error());
    
    
    switch(postVar('action'))
    {
        case 'submitlogin':
            submitlogin(postVar('loguser'),postVar('logpass'));
                mysql_close($dbc);
                exit; //Flushing the headers
        break;
    }
    
    function submitlogin($loguser,$logpass)
    {
        if(isset($loguser, $logpass))
        {
            $myusername = mysql_real_escape_string(stripslashes($loguser));
            $mypassword = mysql_real_escape_string(stripslashes($logpass));
    
            $sql = sprintf("SELECT * FROM admin WHERE user='%s' AND password=('%s')",$myusername,$mypassword);
    
            if(false === ($result = mysql_query($sql))
            {
                //Show Database query error and die()
            }
    
            // If result matched $myusername and $mypassword, table row must be 1 row
            if(mysql_num_rows($result) > 0)
            {
                session_register("admin");
                session_register("password");
    
                $_SESSION['name']= $myusername;
    
                header("location:index1.php");
            }else
            {
                header("location:login.php?msg=" . urlencode("Wrong Username or Password. Please retry"));
            }
        }else{
            header("location:login.php?msg=" . urlencode("Please enter some username and password"));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a process in erlang that is supposed to do something immediately after
I have a process in Linux that's getting a segmentation fault. How can I
I have a process x that I want to check for leaks with valgrind
So, I have set up a login page that verifies the user's credentials, and
I have 1 process that receives incoming connection from port 1000 in 1 linux
We have a process that needs to run every two hours. It's a process
Imagine I have a process that starts several child processes. The parent needs to
I have a login form in every page of a website so the user
i am autpmating a web site that have different function page. i am making
I have a JSP page that has 2 forms running on Tomcat 6. One

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.