Solved

php queston

Posted on 2013-12-06
8
537 Views
Last Modified: 2014-01-08
I'm saving some text areas to a database and if they are empty I'm ending up with '0' in the field in the DB.

the default value is null for the field (mysql).  How can I format the variable before sending it to the database to not show zero.. can I insert a null value?  

My alternative is to live with the zeros and handle them either in the view php (mvc) or in a jquery script to replace with and empty string.  Seems kind of cheesy to do it that way though.

How can I do this properly in php before I send it to the db?

(FYI it's php within CodeIgniter)
0
Comment
Question by:tf2012
8 Comments
 
LVL 13

Assisted Solution

by:haloexpertsexchange
haloexpertsexchange earned 125 total points
ID: 39701968
you need to add php as a topic for this question to get the experts from that area instead of javascript.
You should be able to piece together a query that says in case of an empty string '' insert NULL instead.
<Link to non-authoritative competing site deleted as per EE guidelines by COBOLdinosaur, Topic Advisor>
0
 
LVL 53

Assisted Solution

by:COBOLdinosaur
COBOLdinosaur earned 125 total points
ID: 39702461
A default null is binary 0 that presents as 0.

For a text field the normal default is empty; so why do you need a default idf you don't really have a value, and default null gives you a problem.

Cd&
0
 
LVL 31

Assisted Solution

by:Marco Gasi
Marco Gasi earned 125 total points
ID: 39702744
tf2012, can you post here the CREATE query of your table? It seems there is something wrong in the table definition and seeing this cold help us to identify the problem.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 125 total points
ID: 39702836
We also need to see the codeigniter code for the controller and the model
0
 
LVL 1

Author Comment

by:tf2012
ID: 39721933
I'll post the codeigniter code bits here tomorrow when I'm back on the project thanks for waiting!
0
 
LVL 1

Author Closing Comment

by:tf2012
ID: 39765756
I got it sorted out, thank your  for waiting
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question