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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:19:51+00:00 2026-05-29T22:19:51+00:00

Someone recently hacked my PHP CMS and planted an SQL injection. Is there a

  • 0

Someone recently hacked my PHP CMS and planted an SQL injection. Is there a way to make my login code more protected and prevent hackers? Any help would be great, thanks.

Login Form

<div id="loginform">

  <form method="post" action="check-login.php" name="form1">

    <label for="username" /><span style="color:#FFFFFF; font-family:'Trebuchet MS', Arial, Helvetica, sans-serif;">username:</span></label>

    <input type="text" name="myusername" id="username"/>

    <label for="password"/><span style="color:#FFFFFF; font-family:'Trebuchet MS', Arial, Helvetica, sans-serif;">password:</span></label>

    <input type="password" name="mypassword" id="password"/>

    <label for="submit"></label>

    <input type="submit" name="sumbit" value="Login">

  </form>

</div>

PHP

mysql_connect ($host, $username, $password) or die ("can't connect");
mysql_select_db ($db_name) or die (mysql_error());

$myusername = $_POST['myusername'];
$mypassword = $_POST['mypassword'];

$sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result = mysql_query($sql);

$count = mysql_num_rows($result);
if ($count == 1){
 session_register("myusername");
 session_register("mypassword");
 header("Location:cms/admin.php");
}else{
 echo "Wrong username or password";
}
  • 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-29T22:19:52+00:00Added an answer on May 29, 2026 at 10:19 pm

    Wow. This is a big no-no:

    $myusername = $_POST['myusername'];
    $mypassword = $_POST['mypassword'];
    

    You need to sanitize these inputs with at least mysql_real_escape_string.

    Change it to this:

    $myusername = mysql_real_escape_string($_POST['myusername']);
    $mypassword = mysql_real_escape_string($_POST['mypassword']);
    

    htmlentities() and htmlspecialchars() are also useful but I would advise against using them on data going into a database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I was repairing someone's code. There was a big class that would not
I recently saw someone with a T-shirt with some Perl code on the back.
I recently came across this in some code - basically someone trying to create
I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and
I've recently been working with someone else's code and I realized that this individual
Someone recently said that I can use Linq to SQL in my application even
I read a post recently where someone mentioned that there is no need for
I have started developing a webpage and recently hired someone to write code to
Ran across this recently and wondering if someone out there can give me a
Someone recently told me, In the past, Google never indexed PHP pages. I don’t

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.