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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:00:32+00:00 2026-05-22T20:00:32+00:00

Starting out with php, I have written a basic authentication script which prints out

  • 0

Starting out with php, I have written a basic authentication script which prints out a list of database on a mysql server if a userid (supplied by user) exists in the user table of “test” database.

The problem is that this script outputs database list even if the userid does not exist in the database. I am not sure what’s wrong with the script. pls look through the script and help me understand as to why the db list is being outputted even though the userid does not exist in the db. Here is the script:

<?php

if(isset($_POST['submitted']))
{
  $userid=$_POST['userid'];
  $userpassword=$_POST['userpassword'];
  $link_id=mysql_connect("localhost","root","pass");
  $result_db_list=mysql_list_dbs($link_id);
  mysql_select_db("test",$link_id);
  if(!($result_ptr=mysql_query("Select userid from user where Userid='$userid'",$link_id))) die ("Please enter correct userid");
     while($test=mysql_fetch_row($result_db_list))
      {
       echo $test[0]."<br>";
      } 

}
else
{
?>

<!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=utf-8" />
<title>Authentication Script</title>
<style type="text/css" >
  #header{
  padding-top:0px;
  margin:0px;
  background-color:#CCCCCC;
  }
  .container{
  width:950px;
  margin:0 auto;
  border:1px solid red;
  }
 .authbox {
 padding-top:100px;
 margin:0 auto;
 }
  #footer{
  background-color:#666666;
  color:white;
}
</style>
</head>

<body>
<div id="header">

<div class="container">

<form action="authentication script.php" method="post">
<div class="authbox">UserName: <input type="text" name="userid" /><br/>
Password: <input type="password" name="userpassword" /><br/>
<input type="hidden" name="submitted" value="true" />
<input type="submit" value="Submit" />
</div>
</form>


</div>

</div>

<div id="footer">
Copywright 2010 NT Technologies. 
</div>

</body>
</html>

<?php
}
?>

Thanks
rseni.

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

    Your script is full of errors. (I hope at least you have magic_quotes on otherwise you are in very big problem. Notice you should avoid anyway magic_quotes and use Prepared Statement)

    That’s happen because of

      if(!($result_ptr=mysql_query("Select userid from user where Userid='$userid'",$link_id))) 
         die ("Please enter correct userid");
    

    That’s query doesn’t return FALSE if it doesn’t select nothing.

    You should change it to:

    $result = mysql_query("SELECT COUNT(*) as countUser [etc]");
    $r = mysql_fetch_assoc($result);
    if ($r['countUser']==0) 
      die('Denied');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.