Jump to content

[SOLVED] grab first 2 numbers from a field and put into new field?


Recommended Posts

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

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.

 

 

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)" );

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.