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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:43:45+00:00 2026-06-01T15:43:45+00:00

I am using prepared statements to store, retrieve and update data to or from

  • 0

I am using prepared statements to store, retrieve and update data to or from the database. Do I need to use htmlspecialchars() or htmlentities() if I am using prepared statements?

From what I understand, you dont need to use htmlspecialchars() when inserting data and it only concerns html that is outputted…

I have a situation where I am using a prepared statement to store user input from a register form like so:

$stmt = $conn2->prepare("INSERT INTO users (username, email, password) VALUES (?, ?, ?)");
$stmt->bind_param('sss', $username, $email, $password);
$stmt->execute();

I have another script that is retrieving the username and password when logging in and displaying their username on screen like so:

$stmt = $conn2->prepare("SELECT username FROM users WHERE username = ? AND password = ?");
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
$stmt->store_result();

if ($stmt->num_rows == 1) {

$stmt->bind_result($name);
$stmt->fetch();

I have also put the username in a SESSION and echoed the session like so:

echo $_SESSION['user']['username']

From this example, do I need to use htmlspecialchars() or htmlentities() when displaying the username? Is this what is meant by outputting the HTML?

If so, where would I implement htmlspecialchars() or htmlentities()??

  • 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-01T15:43:46+00:00Added an answer on June 1, 2026 at 3:43 pm

    Databases don’t care about HTML.

    Use one of them if you are inserting the data into an HTML document, and do so immediately before inserting into an HTML document (not immediately before inserting into a database, you might need the raw data again for some other purpose).

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

Sidebar

Related Questions

I am trying to insert and update data using 3 prepared statements. There are
I am trying to select from a mySQL table using prepared statements. The select
right now im using prepared statements, to select / insert data to mysql. Ok
I'm using prepared statements and MySQLi, and am currently getting this error. PHP Catchable
I've been using prepared statements for a little while now and I've never had
I know using prepared statements helps to avoid sql-injection. My problem is, that a
I've got a Doctrine_RawSql query using prepared statements. However, they seem to get ignored
I'm writing some DB routines and I'm using prepared statements. My environment is PDO
Possible Duplicate: PDO Prepared Statements I'm using the mysqli extension in PHP and I'm
What is the importance of using: $stmt->free_result(); $stmt->close(); After a database call using prepared

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.