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

  • Home
  • SEARCH
  • 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 6997021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:13:52+00:00 2026-05-27T20:13:52+00:00

I’m getting errors with the PHP login script I am using on my site.

  • 0

I’m getting errors with the PHP login script I am using on my site.

I wanted to add code which checks if the user is banned when he/she logs in.

But for some reason(s), it’s not working properly; it always outputs “You are banned,” even if the ban field/attribute contains on “n” for false in the MySQL “users” table.

I’ve tried fixing the code, but I still get errors. This is my code:

$bancheck = mysql_query("SELECT * FROM users WHERE ban = '".$_POST['username']."'" ) or die(mysql_error());
$ban = mysql_fetch_array($bancheck);    

if ($ban = 'y') {
  die('You are banned...');
}

The MySQL field which I’ve to check against is called “ban” and value is either “y” for “true,” or “n” for “false.”

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

    1: Should be a comparison, not an assignment.

    This line is incorrect:

    if ($ban = 'y') {{
    

    It should be:

    if ($ban == 'y') {
    

    I’m assuming there’s an extra brace there by accident also.


    2: SQL injection

    You should not pass your string straight from $_POST into your MySql as you are vulnerable to SQL injection. You should escape it like so:

    $bancheck = mysql_query("SELECT * FROM users WHERE ban = '".mysql_real_escape_string($_POST['username'])."'" )or die(mysql_error());
    

    3: Ban != user

    You should not compare ban to the username passed in via the form anyway, as ban will either hold the string ‘y’ or ‘n’. You should compare the username (passed in) to the approriate username field in your database table. Like so:

    $bancheck = mysql_query("SELECT * FROM users WHERE username = '".mysql_real_escape_string($_POST['username'])."'" )or die(mysql_error());
    

    4: Proper iteration & comparison

    Instead of the mysql_fetch_array() function I’d use the mysql_fetch_assoc() function because it returns an associative array.

    This will return an associative array for each row returned (contained in the MySql resource $bancheck) so you need to iterative through them (even though it should only return one array) like so:

    while($ROW = mysql_fetch_assoc($bancheck))
    {
        if('y' == $ROW['ban']) {
    
            die('You are banned...');
        
        }
    }
    

    But I’d add in some more code just to help with any other problems:

    $count = mysql_num_rows($bancheck);
    if($count > 1)
    {
        die('More than one user with that username');    
    }
    elseif($count > 0)
    {
        while($ROW = mysql_fetch_assoc($bancheck))
        {
            if('y' == $ROW['ban']) {
    
                die('You are banned...');
            
            }
        }
    }
    else //i.e. $count<=0
    {
        die('No users with that username');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
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
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I would like to count the length of a string with PHP. The string

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.