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 9148937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:24:21+00:00 2026-06-17T11:24:21+00:00

I’m learning PHP and am having issues getting the following code to work properly.

  • 0

I’m learning PHP and am having issues getting the following code to work properly. Basically the login page displays correctly, and without errors and the variables appear to be assigned correctly, but upon page reload I just get the same login form, it appears the data has either not been passed and is therefore not being acted upon.

I’ve looked at the code over and over again and even tried a different method (produced same result!) so it’d be lovely if someone helpful could spend a minute and point me in the right direction.

One thing that might be an issue is my server is running 5.3.9 and the book I’m working from is PHP5 so maybe some of the function I’m calling have been deprecated. Which would be a pain…

    <?php 
include_once "common_db.inc";
$register_script = "register.php";

if (!isset ($userid)) {
    login_form();
    exit;
} else {
    session_start();
    session_register ("userid", "userpassword");
    $username = auth_user ($_POST['userid'], $_POST['userpassword']);

    if (!$username) {
        $PHP_SELF = $_SERVER['PHP_SELF'];
        session_unregister ("userid");
        session_unregister ("userpassword");
        echo "Failed to authorize. " .
                "Enter a valid DX number and password." . 
                "Click the link below to try again.<br>\n";
        echo "<a href=\"$PHP_SELF\">login</a><br>";
        echo "Click the following link to register<br>\n";
        echo "<a href=\"$register_script\">Register</a>";
        exit;
    } else {
        echo "Welcome, $username!";
    }
}

function login_form() 
    {
        global $PHP_SELF;
?>

<form method="post" action="<?php echo "$PHP_SELF"; ?>">
    <div align="center"><center>
        <h3>Please login to use the page you requested</h3>
        <table width="200" cellpadding="5">
            <tr>
            <th width="18%" align="right" nowrap>id</th>
            <td width="82%" nowrap>
                <input type="text" name="userid" />
            </td>
            </tr>
            <tr>
            <th width="18%" align="right" nowrap>password</th>
            <td width="82%" nowrap>
                <input type="password" name="userpassword" />
            </td>
            </tr>
            <tr>
            <td colspan="2" width="100%" nowrap>
                <input type="submit" value="login" name="Submit" />
            </td>
            </tr>
            </table>
            </center>
            </div>
</form>

<?php
    }
    function auth_user($userid, $userpassword)
    {
        global $dbname, $user_tablename;
        $link_id = db_connect($dbname);
        $query = "SELECT DXNumber FROM $user_tablename WHERE DXNumber = '$userid'
                                  AND userpassword = password ('$userpassword')";
        $result = mysql_query ($query);

        if (!mysql_num_rows($result)){
            return 0;
        }else{
            $query_data = mysql_fetch_row($results);
            return $query_data[0];
        }
    }
?>
  • 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-06-17T11:24:21+00:00Added an answer on June 17, 2026 at 11:24 am

    You’re not defining $userid or checking if the form has been submitted. Try:

    if (!isset($_POST['userid'])) {
    

    Your query in your auth_user function needs to look like this:

    $query = "SELECT DXNumber FROM $user_tablename WHERE DXNumber = '$userid' AND userpassword ='" . $userpassword."'";
    

    Also, you’re open to sql injection. You should look into using PDO and prevent it.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
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 interested in microtypography issues on the web. I want a tool to fix:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.