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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:30:21+00:00 2026-05-24T07:30:21+00:00

Error I’m getting: Whether I try a valid username or password, it always says

  • 0

Error I’m getting: Whether I try a valid username or password, it always says “Sorry, username already exists” . Is something wrong with my logic, specifically with this code block:

 $q = $conn->query("SELECT uname FROM Student WHERE uname= $aRegUsr ");
    $stmt = $conn->prepare($q);
    $stmt->fetch($q);
    if($stmt > 0){ #if there are 1 or more users with enter username, deny.

dbcred.php

<?php
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'databasename';

?>

PHP:

<?php
#Login Details
require_once('dbcred.php');
$conn = new PDO("mysql:host=$host;dbname=$db", $user, $pass);

$aRegUsr = $_POST['regduser']; 

#Check for Existing User
$q = $conn->query("SELECT uname FROM Student WHERE uname= $aRegUsr ");
$stmt = $conn->prepare($q);
$stmt->fetch($q);
if($stmt > 0){ #if find that username in use, deny ability to register, else{ALLOW}
echo "Sorry, username already exists";
}
else{
echo "Success";
}

?>

HTML

<form action="inc/check_regUsr.php" method="post" id="userLogon">
    <div class="field required">
        Username: <input type="text" name="regduser" tabindex="1" /><br />
        </div>
        <div class="field required">
        Password: <input type="password" name="regdpass" tabindex="2" /><br />
        </div>
        <input type="submit" name="submitUser" />
</form>

DB Table: Student
img1

  • 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-24T07:30:22+00:00Added an answer on May 24, 2026 at 7:30 am

    Are you trying to create a user registration or user authentication script? I don’t believe your actual purpose is clearly outlined to help provide an effective solution.

    “Whether I try a valid username or password” indicates user authentication, whereas “if($stmt > 0){ #if there are 1 or more users with enter username, deny.” indicates user registration.

    EDIT: Based off of your updated requirements, user authentication can get a bit complicated depending on your deployment’s security. Included below is sample code based off of your base code. Please note that you may want to find a pre-built script and modify it for your needs as this may serve your purpose better.

    <?php #Login Details 
    require_once('dbcred.php'); 
    
    #Variables
    $error = '';
    $auth = 0;
    $aRegUsr = $_POST['regduser'];   #Check for Existing User 
    $aRegPass = $_POST['regdpass'];   #Check for Existing User 
    
    #DB stuff
    $conn = new PDO("mysql:host=$host;dbname=$db", $user, $pass); 
    $sql = "SELECT uname,password FROM Student WHERE uname= $aRegUsr ";
    
    #Dataset stuff
    foreach($conn->query($sql) as $row){ 
        if($row['password'] != $aRegPass){
            $error = 'Invalid Password';
            $auth = 0; #If $auth = 0 then user is logged in
        }else{
            $auth = 1; #If $auth = 1 then user is logged in
        }
    }
    $conn = null;
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Error: 155004 (Attempted to lock an already-locked dir) Description: Working copy '/Users/Carrie/MyProjects/Sandbox/Flip/Classes' locked
error CS0266: Cannot implicitly convert type 'object' to 'int'. An explicit conversion exists (are
Error 7 The type 'System.Web.Routing.RouteValueDictionary' exists in both 'c:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.dll' and 'c:\WINNT\assembly\GAC_MSIL\System.Web.Routing\3.5.0.0__31bf3856ad364e35\System.Web.Routing.dll' c:\Projects\VS\solutionfolder\projectfolder\Views\group\List.aspx
Error im getting: An unhandled exception of type 'System.StackOverflowException' occurred in System.Management.dll My callstack:
Error message : svn: Can't open file '/Users/username/Projects/myproject/trunk/project/.svn/text-base/filetoupdate.h.svn-base': No such file or directory Question:
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
Error CS0266: Cannot implicitly convert type 'object' to 'Microsoft.Office.Interop.Excel.Range'. An explicit conversion exists (are
Error 1 A local variable named 'userin' is already defined in this scope myclass.fillAccounts();
Error : Unable to add cookies, header already sent. I would like to know
Error message: fatal: git checkout: updating paths is incompatible with switching branches/forcing How to

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.