Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2010
    Posts
    136

    Unanswered: problem in datatype

    Hi..

    I input numbers in textboxes.
    When I did not input number in my textbox or textbox is blank and i click save it save as 0.00 I used double data type.

    I want to happen is if I did not input number or data in my textbox no datra will save in my database.

    THank you

  2. #2
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    Check whether your create table script includes a default value. What this means is that if you do not enter a value for this field it will populate it with the default. I suspect that you have default value set to 0.
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  3. #3
    Join Date
    Dec 2010
    Posts
    136
    My default is NULL yet it save as 0.00 because my datatype is Double (23,2)

    Thank you

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    this is not a mysql problem

    your php code is responsible for entering the textbox value into the table

    if you don't want a value, make sure that it doesn't enter one
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    you must validate any user data
    so make use of the various PHP functions such as is numeric
    never trust what you odn't control, and in the internet world that means anythign outside your script, and especially anythign that is going to hit your db.

    if you are accepting user data to be entered into a db then you must consoder the security implications of that and use things like escape strings
    Google
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by r937 View Post
    this is not a mysql problem

    your php code is responsible for entering the textbox value into the table

    if you don't want a value, make sure that it doesn't enter one
    But in that case the program must send a NULL value explicitely because in a default installation MySQL will silently assign a default value if the column is not specified during insert even if it's defined as not null:

    Code:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 2
    Server version: 5.5.9 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> create table some_number (id integer primary key, some_value double not null);
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> insert into some_number (id) values (1);
    Query OK, 1 row affected, 1 warning (0.01 sec)
    
    mysql>
    mysql> select *
        -> from some_number;
    +----+------------+
    | id | some_value |
    +----+------------+
    |  1 |          0 |
    +----+------------+
    1 row in set (0.00 sec)
    
    mysql>
    Seeing newphpcoder talking about 0.00 value assigned I wonder if the PHP code is so smart to not sent columns where no input was done.

  7. #7
    Join Date
    Dec 2010
    Posts
    136
    Quote Originally Posted by r937 View Post
    this is not a mysql problem

    your php code is responsible for entering the textbox value into the table

    if you don't want a value, make sure that it doesn't enter one
    Do you know what code should I used for validating entering textbox,

    Thank you

  8. #8
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    sorry, man, you should know by now, i've told you before, i don't do php
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  9. #9
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by newphpcoder View Post
    Do you know what code should I used for validating entering textbox,

    Thank you
    try reading post #5 and following the links there
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •