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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:19:19+00:00 2026-05-23T06:19:19+00:00

I’ve done quite a bit of research and preparation with my code to try

  • 0

I’ve done quite a bit of research and preparation with my code to try and prevent SQL injections, but I wanted to discuss something that I’m not quite sure about.

I understand the the mysqli_real_escape_string does not escape _ (underscore) and % (percent) characters. If I’m not using any LIKE clauses in my SQL statements, does this open me up to any risk?

Below is an example of one the instances I’m interested in talking about. Here is the login script I’m using. I want to make sure that I’m not opening myself up to any injection vulnerabilities here. Your insight and feedback would be greatly appreciated.

// Initiate login process if the mode is set to login
if ($_REQUEST['mode'] == "login") {

    // Open shared database connection
    $cxn = connectDb();

    // Escape characters to help prevent a SQL injection attack
    $username = mysqli_real_escape_string($cxn, $_POST['user']);

    // Convert submitted password to hashed value using 
    // custom password hashing function
    $password = custompwhash($_POST['pass']);

    // Execute SQL statement to determine if the credentials provided 
    // match a valid user
    $sql = "SELECT count(*) as countOK FROM user_def WHERE ".
            "username = '$username' AND password = '$password'";
    $result = mysqli_query($cxn,$sql);
    $row = mysqli_fetch_array($result);
    extract($row);

    // If the username value submitted is null, throw and error
    if ($username == "") {
        die2("Please enter your username and try again.<br />");
        failedloginalert($username);
    }

    // If the password value submitted is null, throw and error
    else if ($password == "") {
        die2("Please enter your password and try again.<br />");
        failedloginalert($username);
    }

    // If the credenetials provided match a valid user in the database, 
    // initate login
    else if ($countOK == '1') {    
        $sql2 = "INSERT INTO `user_activity` (`username`, `time`, `ip`)".
                " VALUES ('$username', NOW(), '{$_SERVER['REMOTE_ADDR']}')";
        $result2 = mysqli_query($cxn,$sql2);
        $_SESSION['auth'] = 1;
        $_SESSION['username'] = $username;

        // If the user does not need to be directed to a specific page, direct to home.php
        if (empty($_GET['page'])) {
            die2("<span style='color:#000;'>You have successfully logged in. <br /><br />
            Please click <a href=\"/admin/home.php\">here</a> if you are not automatically redirected.</span>
            <meta http-equiv='refresh' content='0;url=home.php'/>");
            die();
        }

        // Otherwise, if the user does need to be directed to a specific page, direct to the requested page
        else {
            $loginredirectpage = $_GET['page'];
            die2("<span style='color:#000;'>You have successfully logged in. <br /><br />
            Please click <a href=\"/admin/home.php\">here</a> if you are not automatically redirected.</span>
            <meta http-equiv='refresh' content='0;url=".$loginredirectpage."'/>");
            die();
        }
    }

    // Since the credenetials provided do not match a valid user in the database, throw an error
    else { 
        die2("The username or password you entered is invalid. Please try again. <br/><br/>If the problem persists, <a href=\"/user/resetpassword.php\" class=\"red\">reset your password</a>.");
        failedloginalert($username); 
    }
}
  • 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-23T06:19:20+00:00Added an answer on May 23, 2026 at 6:19 am

    If I’m not using any LIKE clauses in
    my SQL statements, does this open me
    up to any risk?

    No it doesn’t. = just gives you more exact answer than LIKE

    SQL Injection is more to do with quote sign ' " since the technique tries to append on the query string. So I’d say % and _ won’t open up any security risk if you filtered all the possible quotes. In this case, mysqli_real_escape_string() can help.

    PDO is an abstraction layer that assists you with dealing with databases more efficiently. It can help you with SQL injection, but I don’t recommend using it unless you’re building something big that requires a lot of interaction with database.

    So final my point is your code looks ok (:

    • 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
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to construct a data frame in an Rcpp function, but when I

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.