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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:41:52+00:00 2026-05-17T00:41:52+00:00

I have a simple contact form with name, email, a select list, and textarea.

  • 0

I have a simple contact form with name, email, a select list, and textarea. In my mailer php script I’m trying to add a simple filter to prevent SQL injection or other forms of hacking.

For example, I’m using

$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_SPECIAL_CHARS);

Is this good?

  • 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-17T00:41:53+00:00Added an answer on May 17, 2026 at 12:41 am

    Firstly let me tell you that about 85% of protection methods are done with 2 functions.

    • htmlspecialchars
    • mysql_real_escape_string

    Firstly if someone sends some data to your site such as $_POST['name'], and you wish to use this value back on html side such as <p>The following string: {$_POST['name']} is invalid</p> then you should ALWAYS make sure that that value has been through htmlspecialchars, this will protect most of XSS Attempts

    Next is injection, if the value of $_POST['name'] is going into your database just make sure that you use mysql_real_escape_string on that value.

    that will give you 100% protection from sql injection, but all that means is your db cannot run commands from the user, that dont mean that the text is what it should be.

    The functions that you should always use before inserting data into your database are

    • empty() or isset()
    • trim()
    • strlen()
    • preg_match()
    • filter_var and filter_input

    This is called Validation and is only needed for yout to make sure the data the user is submitting is what you want such as filter_var would be used to validate that the email they entered is an email and not just some blah blah

    What i usually tent do do is to run a clean function to make sure that all imputed data is clean with htmlspecialchars

    example:

    function clean($array)
    {
        foreach($array as $key => $val)
        {
            if(is_array($val))
            {
                $array[$key] = clean($val); //Recursive 
            }else
            {
                $array[$key] = htmlspecialchars($val, ENT_QUOTES);
            }
        }
        return $array;
    }
    

    Then do the following to make sure that your safe from XSS:

    $_GET = clean($_GET);
    $_POST = clean($_POST);
    

    So if someone tried to submit <a href='test'>Test</a> then the value would be converted to &lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt

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

Sidebar

Related Questions

i have developed a simple php contact form, that's working fine, but i am
I have a contact us form in my iphone application. with first name last
I had this simple modal contact form working fine but must have broke it
I have a very simple contact form on my site, Im looking for users
I have a simple contact form: <div class=contact-wrapper> <div class=grid_8 contact-form-wrapper> <form id=contactus method=GET
I have a simple contact page set up with a form and I am
Say I have this simple form: class ContactForm(forms.Form): first_name = forms.CharField(required=True) last_name = forms.CharField(required=True)
We have a simple domain model: Contact, TelephoneNumber and ContactRepository. Contact is entity, it
I have simple regex \.*\ for me its says select everything between and ,
I have a simple cakephp form WITH validation that submits to a database. It

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.