简体   繁体   English

PHP/MYSQL 更新特定用户问题中的特定行

[英]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.我目前正在建立一个预测游戏网站,其中人们 select 特定问题的特定答案,他们从网站上的 <select> 表单中选择答案。 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.上次我这样做时,我让人们也从 <select> 字段中选择他们的用户名和密码,然后当他们输入他们的答案时,它将它与用户名匹配并使用它更新数据库。

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.对于这个更新版本,我已经让用户事先登录,所以我已经在 session 中找到了他们的名字,因为它在页面上的其他地方使用过。

How do I go about updating their specific row in the database for a specific field.我如何 go 关于更新数据库中特定字段的特定行。 (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.用户已登录,他们在数据库中的名字是 Jerry,我已经声明了他们。

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.所以现在登录,他们从 go 到一个事件,然后从 select 框中选择他们的选择。

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.所以我想更新“Jerry”行并将他们从 select 框“世界杯”中的选择放入“世界杯”字段。 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.也总会有超过 1 个字段要更新,每次更新可能大约 10 个字段,他们可以随时更新。

Does that make sense?那有意义吗?

I think you want to use an UPDATE query.我认为您想使用 UPDATE 查询。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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