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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:09:40+00:00 2026-05-25T03:09:40+00:00

I’m using a prepared statement to insert some values into my table. Before doing

  • 0

I’m using a prepared statement to insert some values into my table. Before doing so, i’m validating the fields. Some fields are empty and therefore need to remain NULL.

For some reason, on my local development environment, when the field is not initialize, the field in the database remains null… but, on my live development, when a field is not initialize, the field in the database changes to a blank when it’s a varchar and 0 when it’s a int.

Why is that? I want to remain NULL if no values has been entered in the form!

this is what mysql looks like:

CREATE TABLE album (
   album_id smallint unsigned not null auto_increment,
   title varchar(75) not null,
   subtitle varchar(75),
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

my php script to validate the data:

// validation
$warning = array();

// validate title (required)
$title = trim($_POST['title']);

if ($title == '') {
   $warning['title'] = 'The title is a required field';
}

// validate subtitle if exists (optional)
if (trim($_POST['subtitle']) != '') {
   $subtitle = trim($_POST['subtitle']);
}

my php script if validation passed!

if (!warning) {
   $sql = 'INSERT INTO album (title, subtitle, created) VALUES(?, ?, NOW())';
   $stmt->prepare($sql);
   $stmt->bind_param('ss', $title, $subtitle);
   $stmt->execute();
   $stmt->free_result();

   if ($stmt->affected_rows > 0)
      echo 'Success!';
   else
      echo 'Failed!';
}

If the subtitle has no value (not even set!), shouldn’t the field remain NULL (as defined in the database) instead of a blank field?

That’s what i thought when designing the model in my local env. But, once on my live site, the reaction is completely the opposite?

Help! How do i make it so it remains NULL and not a blank field…

Thanks in advance

  • 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-25T03:09:41+00:00Added an answer on May 25, 2026 at 3:09 am

    What’s your database framework? both systems with same version?

    Seems that you PDO bind_params don’t work fine with PDO::bindValue with PDO::PARAM_NULL data_type in one of your systems.

    http://php.net/manual/en/pdostatement.bindvalue.php

    Edit – 1 —

    Ops, and your SQL sentence seems wrong:

     INSERT INTO album (title, subtitle, created) VALUES(?, ?, ?, NOW())';
    

    four values for three fields.

    Edit – 2 —

    I supose that you do:

     $stmt = $mysqliConn->prepare($sql);
     $stmt->bind_param('ss', $value1, $value2);
    

    and previously

     $value2 = null;
    

    If it is null. In your code you don’t assign any value, try to force to assign null.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am using Paperclip to handle profile photo uploads in my app. They upload
In order to apply a triggered animation to all ToolTip s in my app,
I want use html5's new tag to play a wav file (currently only supported
I want to count how many characters a certain string has in PHP, but
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

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.