简体   繁体   中英

PHP/MYSQL Update Specific Rows in Specific User Question

I'm currently building up a prediction game website, in which people select specific answer for specific questions, they choose the answers from a <select> form on the website. Last time I did this, I got the people to choose their username and password from <select> fields too, and then when they put their answers in, it matched it to the username and updated the database using that.

For this updated version, I've got the users to log-in before hand, so I already have their name in a session available to me as it's used elsewhere on the page.

How do I go about updating their specific row in the database for a specific field. (Question probably doesn't make sense, so I'll give an example).

The user is signed in, their name in the database is Jerry and I've got them declared already.

session_register("name");

So there logged in now, they go to an event and from the select box which has the name 'World Cup' they choose their pick.

Now I want to update their specific row in the database and update the field 'World Cup' with their pick. How do I go about updating their row using what I've already got for their "name".

So I want to update the row "Jerry" and put their selection from the select box "World Cup" into the "World Cup" field. There will always be more than 1 field to update as well, probably around 10 fields per update which they can update whenever they want.

Does that make sense?

I think you want to use an UPDATE query.

UPDATE users
SET email_address='Jerry@yahoo.com', first_name='Jerry', last_name='Seinfeld'
WHERE username='JSeinfeld'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM