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

  • Home
  • SEARCH
  • 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 7591423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:38:49+00:00 2026-05-30T20:38:49+00:00

I’m relatively new to PHP and have exhausted the internet trying to find an

  • 0

I’m relatively new to PHP and have exhausted the internet trying to find an answer to this problem. I’ve looked at countless examples but people seem to very different login systems to mine and I have trouble deciphering it.

Here is my code so far:

index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Video for Education Log In</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>



<body>
<div id="wrapper">
<div id="header">
    <div id="logo">
        videoedu.edu    </div>
    <div id="menu">
        <ul>
            <li><a href="account.html" class="menua">Create Account</a></li>
            <li><a href="about.html" class="menua">About Us</a></li>
        </ul>
    </div>
</div>
<br><br><br><br>
<div id="page">

<div id="content">
    <h2>Video for Education helps you connect and share with the videos in your life.</h2>
    <h3>Upload Share Create Using video for your education purposes. Lecturers Welcome
    Upload Share Create Using video for your education purposes. Lecturers Welcome
    Upload Share Create Using video for your education purposes. Lecturers Welcome</h3>
    <div class= "form">
    <form name="login" method="post" action="checklogin.php">
        Username: <input type="text" name="myusername" id="myusername" class="textb"/><br />
        Password  :  <input type="password" name="mypassword" id="mypassword" class="textb"/><br />
        <br>
        <input type="submit" name="login" value="Login" id="login" class="texta" />
    </form>
    </div>
</div>
</div>
</div>
</body>
</html>

checklogin.php

<?php

$host = "localhost";
$username = "root";
$password = "";
$db_name = "test";
$tbl_name = "members";

mysql_connect("$host", "$username", "$password")or die("Cannot connect.");
mysql_select_db("$db_name")or die("Cannot select DB.");

$myusername=$_POST["myusername"];
$mypassword=$_POST["mypassword"];


    if ($myusername&&$mypassword)
    {

    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
    $myusername = mysql_real_escape_string($myusername);
    $mypassword = mysql_real_escape_string($mypassword);

    $sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
    $result = mysql_query($sql);

    $count = mysql_num_rows($result);

    if($count == 1){
    session_register("myusername");
    session_register("mypassword"); 
    header("location:login_success.php");
        }
    else 
        {
    echo "Wrong Username or Password";
        }
    }

    else

    echo "You have left one or more fields blank.";

?>

login_success.php

<? 
session_start();
if( !isset( $_SESSION['myusername'] ) ){
header("location:account.html");
}

echo "Welcome, ".$_SESSION['myusername']." - You are now logged in.<br>";

echo "<a href=logout.php>Logout</a>"
?>

<html>
<body>

</body>
</html>

logout.php

<?php

session_start();

session_destroy();

echo "You have been logged out, <a href='index.php'>click here</a> to return."

?>

I have tried inserting this into index.html and changing the file name to index.php.

$submit = $_POST["login"];

if($submit)
{

}

…but it just constantly displays one of the errors (‘Wrong username or password’) down the bottom of the page at all times.

I want it so that if the user enters a wrong username or password, or leaves a required field blank, the error will pop up on the same page, instead of going to a new ugly, blank PHP page with the error message in the top left-hand corner.

  • 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-30T20:38:50+00:00Added an answer on May 30, 2026 at 8:38 pm

    In checklogin.php, instead of echoing an error, use this:

    die(header("location:index.html?loginFailed=true&reason=password"));
    

    or something similar, and in your index.html page, just have PHP generate the HTML message, something like this:

        <input type="submit" name="login" value="Login" id="login" class="texta" /><br /><br />
        <?php $reasons = array("password" => "Wrong Username or Password", "blank" => "You have left one or more fields blank."); if ($_GET["loginFailed"]) echo $reasons[$_GET["reason"]]; ?>
    </form>
    

    Also, make sure to die() or exit() when you use header to redirect the page, otherwise the rest of your script continues to run.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.