polardude1983 Posted February 11, 2009 Share Posted February 11, 2009 I have a current_weight field. where ppl have their weight put in there so. if someone enters their weight in the form i have as 228 then the current_weight field says 228 and that works. but what i want is for it to grab the first 2 numbers from current_weight and put it into a field called new_weight. so if someone puts 228 in current_weight, new_weight is 22 if someone puts 180 in current_weight, new_weight is 18 any idea on how to do this? im very puzzled Quote Link to comment https://forums.phpfreaks.com/topic/144740-solved-grab-first-2-numbers-from-a-field-and-put-into-new-field/ Share on other sites More sharing options...
dreamwest Posted February 11, 2009 Share Posted February 11, 2009 If your only dealing with 3 numbers `new_weight` CHAR(2), That will truncate the last number Quote Link to comment https://forums.phpfreaks.com/topic/144740-solved-grab-first-2-numbers-from-a-field-and-put-into-new-field/#findComment-759523 Share on other sites More sharing options...
polardude1983 Posted February 11, 2009 Author Share Posted February 11, 2009 I come up with an error. You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'CHAR(2) mysql_query ( "INSERT INTO members (`username`, `password`, `start_weight_big CHAR(2)`, start_weight_dec) VALUES ('$username', '$password', '$start_weight_big', $start_weight_dec)" ); this is in the php file. I have the html file which gets the user input then calls the php file to input in the database. Quote Link to comment https://forums.phpfreaks.com/topic/144740-solved-grab-first-2-numbers-from-a-field-and-put-into-new-field/#findComment-759694 Share on other sites More sharing options...
polardude1983 Posted February 11, 2009 Author Share Posted February 11, 2009 sorry i mean it was this way and it didn't work. mysql_query ( "INSERT INTO members (`username`, `password`, `start_weight_big` CHAR(2), start_weight_dec) VALUES ('$username', '$password', '$start_weight_big', $start_weight_dec)" ); Quote Link to comment https://forums.phpfreaks.com/topic/144740-solved-grab-first-2-numbers-from-a-field-and-put-into-new-field/#findComment-759702 Share on other sites More sharing options...
polardude1983 Posted February 11, 2009 Author Share Posted February 11, 2009 never mind stupid me.. lol i got it thx sooo much Quote Link to comment https://forums.phpfreaks.com/topic/144740-solved-grab-first-2-numbers-from-a-field-and-put-into-new-field/#findComment-759714 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.