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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:01:53+00:00 2026-05-27T00:01:53+00:00

If I am storing a serialized array to a mysql database should I sanitize

  • 0

If I am storing a serialized array to a mysql database should I sanitize before or after using the serialize function. Or do I even need to sanitize at all?

For example:

$details['name'] = mysql_real_escape_string($_POST['name']);
$details['email'] = mysql_real_escape_string($_POST['email']);
$details['phone'] = mysql_real_escape_string($_POST['phone']);

$serializedDetails = serialize($details);

// Do SQL query

Or

$details['name'] = $_POST['name'];
$details['email'] = $_POST['email'];
$details['phone'] = $_POST['phone'];

$serializedDetails = mysql_real_escape_string(serialize($details));

Or perhaps on the second I can simply do:

$serializedDetails = serialize($details);
  • 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-27T00:01:54+00:00Added an answer on May 27, 2026 at 12:01 am

    Always use mysql_real_escape_string when dealing with strings that might have quotation marks / slashes. If you don’t, you’ll get broken / malicious queries. The output of serialize() sometimes has quotation marks / slashes, so you should use it. There’s no need to serialize the each item of the array beforehand though.

    $details['name']  = $_POST['name'];
    $details['email'] = $_POST['email'];
    $details['phone'] = $_POST['phone'];
    
    $serializedDetails = mysql_real_escape_string(serialize($details));
    

    Just as an example: serializing “hello” will give you: s:5:"hello".

    $data  = 's:5:"hello"';
    $query = 'INSERT INTO tbl (data) VALUES ("' . $data . '")';
    
    // leads to a syntax error from mysql
    // (plus it's a huge security hole)
    mysql_query($query);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What are the advantages and disadvantages of storing JSON data in MySQL database vs.
I'm particularly interested in the following features: possibility of modifying the serialized array using
The array in the database is stored as a serialized string, such as this:
I'm storing a list of items in a serialized array within a field in
I have some Java's serialized objects (arrays of doubles) in MySql database fields that
Is it possible to serialize an object into a string or a byte array
I need to serialize/de-serialize some objects into/from string and transfer them as just opaque
Everything I've read says that storing serialised arrays in Mysql is a bad idea
this is my string in serialized form.when i tried to unserialized (convert to array)
I need to store a multi-dimensional associative array of data in a flat file

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.