php queston

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)
LVL 1
tf2012Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Chris StanyonConnect With a Mentor Commented:
We also need to see the codeigniter code for the controller and the model
0
 
haloexpertsexchangeConnect With a Mentor Commented:
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
 
COBOLdinosaurConnect With a Mentor Commented:
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
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
Marco GasiConnect With a Mentor FreelancerCommented:
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
 
tf2012Author Commented:
I'll post the codeigniter code bits here tomorrow when I'm back on the project thanks for waiting!
0
 
tf2012Author Commented:
I got it sorted out, thank your  for waiting
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.