Solved

php queston

Posted on 2013-12-06
8
536 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
The viewer will learn how to count occurrences of each item in an array.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

773 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