Rottingham Posted April 26, 2010 Share Posted April 26, 2010 Hello I'm performing a standard insert: $account = "D347660"; INSERT INTO "table" SET Account='$account' Every insert drops that trailing zero at the end of the account number! How can I make it stop doing that??? Quote Link to comment https://forums.phpfreaks.com/topic/199845-phpmysql-dropping-zeros-on-insert-into/ Share on other sites More sharing options...
de.monkeyz Posted April 26, 2010 Share Posted April 26, 2010 If Account is a varchar field, check the maximum length of the field, if it's longer than that string that's why, since I see no other reason for it to be removed. Quote Link to comment https://forums.phpfreaks.com/topic/199845-phpmysql-dropping-zeros-on-insert-into/#findComment-1048971 Share on other sites More sharing options...
Rottingham Posted April 26, 2010 Author Share Posted April 26, 2010 I've done that. It's a 7 digit number and I set max characters to 7. When I noticed this problem I bumped it up to 8 and it still does that. Quote Link to comment https://forums.phpfreaks.com/topic/199845-phpmysql-dropping-zeros-on-insert-into/#findComment-1048974 Share on other sites More sharing options...
de.monkeyz Posted April 26, 2010 Share Posted April 26, 2010 What happens when you echo out your query in php? Is the trailing 0 still there? And is the datatype of the database a number, or VARCHAR? Quote Link to comment https://forums.phpfreaks.com/topic/199845-phpmysql-dropping-zeros-on-insert-into/#findComment-1048978 Share on other sites More sharing options...
Rottingham Posted April 26, 2010 Author Share Posted April 26, 2010 Yes the zero stays on my echo output. Only drops on the SQL insert. It is VARCHAR(. I'm baffled. I've faced this before I think but can't remember the best solution. I can make the field an INT and it won't do that but I lose my character at the front. Quote Link to comment https://forums.phpfreaks.com/topic/199845-phpmysql-dropping-zeros-on-insert-into/#findComment-1048984 Share on other sites More sharing options...
de.monkeyz Posted April 26, 2010 Share Posted April 26, 2010 If it's mySQL you should check your database table. Try to manually enter the data in something like phpMyAdmin, it should give you a more verbose output if anything is going wrong. Quote Link to comment https://forums.phpfreaks.com/topic/199845-phpmysql-dropping-zeros-on-insert-into/#findComment-1048985 Share on other sites More sharing options...
laPistola Posted April 26, 2010 Share Posted April 26, 2010 is the character the same on all account numbers?? Quote Link to comment https://forums.phpfreaks.com/topic/199845-phpmysql-dropping-zeros-on-insert-into/#findComment-1048989 Share on other sites More sharing options...
Rottingham Posted April 26, 2010 Author Share Posted April 26, 2010 Ok so I figured it out... Another stupid error like most are. There was a sneaky whitespace at the beginning of the string. a simple trim() fixed it... Quote Link to comment https://forums.phpfreaks.com/topic/199845-phpmysql-dropping-zeros-on-insert-into/#findComment-1048993 Share on other sites More sharing options...
de.monkeyz Posted April 26, 2010 Share Posted April 26, 2010 Good ol' whitespace. Gotta love it, the cause of 100% of invisible errors. Quote Link to comment https://forums.phpfreaks.com/topic/199845-phpmysql-dropping-zeros-on-insert-into/#findComment-1048994 Share on other sites More sharing options...
laPistola Posted April 26, 2010 Share Posted April 26, 2010 Haha i have been hit by that one tonight as well! Quote Link to comment https://forums.phpfreaks.com/topic/199845-phpmysql-dropping-zeros-on-insert-into/#findComment-1049001 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.