php - Prepare statement and placeholder value is no set... null or blank field? -


I am using a ready statement to put some values ​​in my table. Before doing this, I am validating the field. Some fields are empty and therefore have to be zero.

For some reason, on my local development environment, when the field does not start, the field in the database remains futile ... but, development on my life, when an area does not start, So the field in the database turns to an empty space when it is a varchar and 0 when it is an int

Why is it so? If a value is not entered in the form then I want to stay faucet!

This is what mysql looks like:

  create table album (album_idlititin not note auto_ignment, title varchar (75) not tap, subtitle varchar (75),) Engine = MyISAM DEFAULT charetate = utf8 COLLATE = utf8_general_ci;   

My PHP script to validate the data:

  // verification $ warning = array (); // Valid Title (required) $ title = trim ($ _ POST ['title']); If ($ title == '') {$ warning ['title'] = 'title is a required field'; } // Verify // subtitle if present (optional) if (trim ($ _ POST ['subtitle']) = '') {$ subtitle = trim ($ _ POST ['subtitle']); }   

If my php script pass validation!

  if (! Alert) {$ sql = '(Include title, subtitle, created) value (?,?, Now ())'; $ Stmt- & gt; ($ SQL) ready; $ Stmt- & gt; Dam_param ('s', $ title, $ subtitle); $ Stmt- & gt; Executed (); $ Stmt- & gt; Free_result (); If ($ stmt-> impression_arrow> 0) echo 'success!'; Else Echo 'Fails!'; }   

If there is no cost of the subtitle (even not set!), Should not remain in the form of the field field (defined in the database) rather than the empty field?

That's what I thought when designing the model in my local env. But, once the response to my live site is completely opposite?

Help!

What is your database infrastructure? Both systems with the same version?

It seems that PDO :: bind value does not work with PDO bind_params PDU :: PARAM_NULL one of your systems in data_type.

Edit - 1 -

Oops, and your SQL sentence looks incorrect:

  Add to album (Title, subtitle, created) value (?,?,?, Now and ()); ';  

Edit - 2 -

I think you do:

  $ stmt = $ mysqliConn- & Gt; Ready ($ sql); $ Stmt- & gt; Dam_param ('ss', $ value1, $ value2);   

and first

  $ value2 = null;   

If it is empty, do not give any value to your code, try to force to assign the tap.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -