INSERT INTO MySQL and PHP -
i have mysql table ( members ) 6 columns ( firstname, lastname, email, username, password, key)
i need insert string key column username admin
how go doing this?
suppose string want insert literal string 'mystring'. update table this:
update `members` set `key` = 'mystring' `username` = 'admin'   some things note:
- i've enclosed column names, such 
key, in identifier quotes (backticks). because know mysql may treat word 'key' sql reserved word, might result in failing parse update query. - this assumes column 
keyhas string datatype, suchtextorchar(20). if doesn't (for example if it'sint), doesn't make sense try update contain string. - i assume column length, if it's 
charorvarchar, long enough contain string (i.e. it's of length @ least 8). if column short contain string i'm trying put in it, mysql either truncate string or issue error message, depending on sql mode. 
alternatively, if there isn't row in table username 'admin', want insert one, use
insert `members` (`username`, `key`) values ('admin', 'mystring')   this statement subject same provisos 1 above. also, columns not null need have values specified (with possible exception of auto-incrementing integer field).
Comments
Post a Comment