Solved

php queston

Posted on 2013-12-06
8
533 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 30

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 42

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now