Simple authentication script in PHP not working
<p>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.</p>

<p>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:</p>

<pre><code>&lt;?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]."&lt;br&gt;";
      } 

}
else
{
?&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Authentication Script&lt;/title&gt;
&lt;style type="text/css" &gt;
  #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;
}
&lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id="header"&gt;

&lt;div class="container"&gt;

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


&lt;/div&gt;

&lt;/div&gt;

&lt;div id="footer"&gt;
Copywright 2010 NT Technologies. 
&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;

&lt;?php
}
?&gt;
</code></pre>

<p>Thanks 
rseni.</p>
