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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:04:02+00:00 2026-05-29T08:04:02+00:00

This is my first time creating a PHP form that will run a MySQL

  • 0

This is my first time creating a PHP form that will run a MySQL query using INSERT INTO to store data in a production DB. Will this pass for “secure” or is it over-kill?

$orderText = $mysqli->real_escape_string(stripslashes(htmlentities((!isset($_POST["order_text"])?"undefined":$_POST["order_text"]))));
$stmt = $mysqli->prepare("INSERT INTO testtable (order_text) VALUES (?)");
$stmt->bind_param('s',$orderText);
$stmt->execute();

I’m not sure how the lack of a SELECT * affects the amount of risk I’m opening myself up to, but it seems like a script that only uses INSERT is safer. True?

  • 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-29T08:04:03+00:00Added an answer on May 29, 2026 at 8:04 am

    There is a great amount of false assumptions in your question.

    1. It is certainly an overkill.
      Let’s examine your extremely-hard-to-read zillion-nested-operator statement:

      • storing word ‘undefined’ makes no sense. A database has a special mark for the undefined fields – a NULL value. Or simply an empty string would be enough.
      • unconditional stripslashes adds nothing to security but may spoil the data.
      • htmlentities has nothing to do with SQL security, may help with site security in other aspects and may spoil the data as well.
      • escaping adds nothing to security and will spoil the data.
    2. You are taking the problem from the wrong end.
      Your primary goal is to format your query properly. Not to defend from imaginary “attackers” but to privent malfunction with most honest data. While properly formatted query will be invulnerable to various attacks just as a side effect.
      Say, real_escape_string has nothing to do with security. It is used merely to format strings. There are no strings (data enclosed in quotes) in your query – thus this function is utterly useless (and even harmful).

    3. In fact, an injection via INSERT is no less disastrous than via SELECT.

    Finally, the right code would be

    $stmt = $mysqli->prepare("INSERT INTO testtable (order_text) VALUES (?)"); 
    $stmt->bind_param('s',$_POST["order_text"]); 
    $stmt->execute(); 
    

    and when printing the order text back to the site, use htmlspecialchars()

    that’s all.

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

Sidebar

Related Questions

This is my first time creating a SVN repository. I am running into problems
This will be my first time creating one of those slider things. I've seen
This is the first time I'm creating an open-source project, and I've decided (based
I'm creating an asp.net MVC app, first time I've done this. I have a
This is my first time using joomla. I don't know if I'm using the
This is the first time ever I'm using AJAX, and I want to do
First time poster, long time lurker :) I have a form setup that posts
Simple php/mysql INSERT such as mysql_query(INSERT INTO dispatch VALUES('1234','$name','$address')); intermittently fails. I've set it
first time creating something like this. How would I create a hotbar type rectangle
I'm creating a simple application using the Kohana PHP framework, just FYI. This is

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.