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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:39:12+00:00 2026-06-09T23:39:12+00:00

Possible Duplicate: What are the best practices for avoiding xss attacks in a PHP

  • 0

Possible Duplicate:
What are the best practices for avoiding xss attacks in a PHP site

I have a form that user can fill in their personal information. The user submits the form and A web service will process these information and store the information in mysql database.

But what if users enter html tag, php code, or javascript in the input field. I would like to prevent that. I know in javascript there’s a method call escapehtml, in php it’s strip_tags.

I just want to know the correct way of disabling the abilities to type html, php, script from input field. Do I use strip_tags for all input I received?If I use strip_tags, how to disable script? Or there is away to do it in mysql?

Thank you

This is the form:

<div>
    <label class='info-title whitetext' for="name">Full Name: </label>
    <input type="text" name="name" id="name" size='25' maxlength="100" required />
</div>

<div>
    <label class='info-title whitetext' for="phone">Phone: </label>
    <input type='text' pattern='\d+' name='phone' id='phone' size='25' maxlength='12' />
</div>

<div>       
    <label class='info-title' for="email">Email: </label>
    <input type="email" name="email" id="email" size='35' maxlength="60" required />
</div>

<div>       
    <label class='info-title' for="address">Address: </label>
    <input type="text" name="address" id="address" size='45' maxlength="50" required />
</div>
  • 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-06-09T23:39:13+00:00Added an answer on June 9, 2026 at 11:39 pm

    Try htmlspecialchars($string);

    That will encode all the HTML tags to character codes (<div> would become &lt;div&gt;, which will be displayed without being parsed as html) This way, script tags cannot be created as well.

    Be sure to clean the content before supplying it to a database though, for example by escaping with mysqli_escape_string() (others will probably advice you to use prepare statements).

    It is most likely not best practice to put HTML character encoded strings into the database, as it simply increases the string size unnecessarily. (And it doesn’t provide protection against SQL injection on its own)

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

Sidebar

Related Questions

Possible Duplicate: What are the best practices for avoiding xss attacks in a PHP
Possible Duplicate: What are the best practices for avoid xss attacks in a PHP
Possible Duplicate: Best practices in error reporting (Mathematica) Assume that I have a function
Possible Duplicate: What are best practices that you use when writing Objective-C and Cocoa?
Possible Duplicate: Best practices to parse xml files? I have a xml string: <XML>
Possible Duplicate: PHP 2-way encryption: I need to store passwords that can be retrieved
Possible Duplicate: Daylight saving time and Timezone best practices Basically I have the following
Possible Duplicate: Best practices for efficiently storing md5 hashes in mysql We use Hex
Possible Duplicate: Best practice: Import mySQL file in PHP; split queries How to import
Possible Duplicate: Best way to find Browser type & version? In HTML/JavaScript, How can

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.