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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:03:40+00:00 2026-06-07T18:03:40+00:00

I’ve finally made what I think is a good, secure and fast way to

  • 0

I’ve finally made what I think is a good, secure and fast way to execute a query, but I want to be completely sure before I implement it all over the site.

My code:

$email = $_POST['email'];
$displayName = $_POST['displayName'];
$pass = $_POST['pass1'];

if($stmt = $link -> prepare("INSERT INTO profiles (email, displayName, password) VALUES (?, ?, md5(?))")) {

        /* Bind parameters
            s - string, b - boolean, i - int, etc */
        $stmt -> bind_param("sss", $email, $displayName, $pass);

        /* Execute it */
        $stmt -> execute();

        echo "You are now registered.<br />";
        echo "<a href=\"login.php\">Login</a>";


        /* Close statement */
        $stmt -> close();
    }

BTW, what does stmt mean/stand for?

EDIT, NEW CODE:

    /* Create a prepared statement */

    $stmt = $link -> prepare("INSERT INTO profiles (email, displayName, password,
    dateRegistered) VALUES (?, ?, md5(?), NOW())");

    if ( false===$stmt ) {
      die('prepare() failed: ' . htmlspecialchars($link->error));
    }

    $rc = $stmt -> bind_param("sss", $email, $displayName, $pass);
    if ( false===$rc ) {
      die('bind_param() failed: ' . htmlspecialchars($stmt->error));
    }

    /* Execute it */
    $rc = $stmt->execute();
    if ( false===$rc ) {
      die('execute() failed: ' . htmlspecialchars($stmt->error));
    }

    echo "You are now registered.<br />";
    echo "<a href=\"login.php\">Login</a>";


    /* Close statement */
    $stmt -> close();
  • 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-07T18:03:42+00:00Added an answer on June 7, 2026 at 6:03 pm

    Yes – it’s a prepared statement which pretty much avoids risk of SQL injection, which is the main purpose behind prepared statements.

    The only downside is they can be troublesome when used in utilities that have to work with different queries, with a dynamic number of fields, say. You can use reflection to get round this, though.

    A few pointers, though:

    • md5 for passwords? Probably not the safest option. Consider using an encryption salt (lots of stuff on this if you Google it)

    • you seem to be taking data straight from the $_POST superglobal without checks or sanisation, but I guess that was just to keep the length of the code snippet down for this SO question. Never insert straight from input to query – there should be a phase of validation/escaping/encoding etc.

    • you don’t seem to be checking that the execution of the statement was successful – you assume it was and then proceed to feedback. Check for errors first.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to show the soap response to UIWebview.. my soap response is, <p><img
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.