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 key has string datatype, such text or char(20). if doesn't (for example if it's int), doesn't make sense try update contain string.
  • i assume column length, if it's char or varchar, 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

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -