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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:08:31+00:00 2026-06-17T05:08:31+00:00

I’m trying to build a login form so an admin I specify in the

  • 0

I’m trying to build a login form so an admin I specify in the database can insert images into my database.

I’m having a few errors:

1) I’m using <?php echo $_SERVER['PHP_SELF']; ?> to call itself (call Login.php) so it will load the PHP code below it (which is in the same file). Whenever I press submit, it doesn’t go to the specified header in the php code, but rather goes back to the homepage.php.

Login.php: Admin Login Form html

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table>
    <tr>
        <td>Username: </td><td><input type="text" name="username"></td>
    </tr>
    <tr>
        <td>Password: </td> <td><input type="text" name="pw"></td>
    </tr>
</table>
<br />
<input type="submit" value="Log in">
</center>

2) The second issue is… looking at the php code, I’m trying to find a function that will let me grab a specific key of an associate array. For example, I run the database query and store it as an associate array in $result, and return that. Then I want to grab a key (“username” and “password”) from users table and compare them to the input from the above html form.

I’ve tried using array_keys, but that needs an array, not an object. So I casted it, and it still won’t work.

I’m using print_r(array_keys($userResult, "username")); to see if it would print the key I wanted.

Login.php Php code

<?php 

$username = isset($_POST['username']) ? $_POST['username'] : "";
$password = isset($_POST['pw']) ? $_POST['pw'] : "";

$userResult = verify($username, $password);
$array = (array)$userResult; //cast to array

print_r(array_keys($userResult, "username"));

if(array_keys($userResult, "username") == "dan" && array_keys($userResult, "password") == "12345") {
    header("Location: ?action=admin");
}
else {
    echo "<center>Incorrect credentials</center>";
}

function verify($user, $pw) {
    include './scripts/dbconnect.php';

    $result = $mysqli->query("SELECT username, password FROM users WHERE username='" . $user . "' AND password='" . $pw . "'"); 

    return $result; 
}

include 'include/footer.php';
?>

Any thoughts would be appreciated!

  • 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-17T05:08:32+00:00Added an answer on June 17, 2026 at 5:08 am

    You can leave action in blank like action="" and it will post in the same page.
    I don’t remember what $_SERVER['PHP_SELF'] returns inside/outside includes but that must be your problem.

    Also, you are alreadly checking the username and password on your query, then you just need to know if it returns a result or dont. Check for the number of rows 🙂

    • 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
We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am using JSon response to parse title,date content and thumbnail images and place
this is what i have right now Drawing an RSS feed into the php,

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.