MySQL 和PHP - 选择/选项列表并向用户显示数据,仍然允许我生成查询

发布于 2024-08-26 20:52:52 字数 1802 浏览 7 评论 0原文

抱歉,标题不清楚,一个示例可以澄清一切:

TABLE: Scenario_victories

ID  scenid        timestamp      userid side    playdate
1   RtBr001   2010-03-15 17:13:36   7     1     2010-03-10
2   RtBr001   2010-03-15 17:13:36   7     1     2010-03-10
3   RtBr001   2010-03-15 17:13:51   7     2     2010-03-10

IDtimestamp 是添加其他 4 个字段时数据库自动插入的。

首先要注意的是,用户可以在同一日期(playdate)记录同一场景(scenid)的多次播放,可能会产生相同的结果(一方=获胜者)。因此需要唯一的 ID 和时间戳来进行良好的衡量。

现在,在他们的用户页面上,我以

我的脚本采用 scenid 并在点击其他一些表后返回一些更用户友好的内容,例如:

  (playdate)   (from scenid)        (from side)
#########################################################
# 2010-03-10  Road to Berlin #1 -- Germany, Hungary won #
# 2010-03-10  Road to Berlin #1 -- Germany, Hungary won #
# 2010-03-10  Road to Berlin #1 -- Soviet Union won     #
#########################################################
     [Delete Record]              [Go To Scenario]

在 HTML 中:

<select name="history" size=3>
  <option>2010-03-10  Road to Berlin #1 -- Germany, Hungary won</option>
  <option>2010-03-10  Road to Berlin #1 -- Germany, Hungary won</option>
  <option>2010-03-10  Road to Berlin #1 -- Soviet Union won</option>
</select>

现在,如果您是突出显示第一条记录并单击Go to Scenario,那里有足够的信息供我解析它并生成您想要查看的确切场景。但是,如果您选择删除记录,则不会 - 我有播放日期,我可以解析scenidside< /code> 所列内容,但在此示例中,所有三个记录都将具有相同的结果。

我似乎把自己逼到了墙角。有人建议我如何获取一些唯一的识别数据(ID 和/或 timestamp)并在此表单上显示而不向用户显示?

请仅限 PHP,我必须符合 NoScript!

Sorry for the unclear title, an example will clear things up:

TABLE: Scenario_victories

ID  scenid        timestamp      userid side    playdate
1   RtBr001   2010-03-15 17:13:36   7     1     2010-03-10
2   RtBr001   2010-03-15 17:13:36   7     1     2010-03-10
3   RtBr001   2010-03-15 17:13:51   7     2     2010-03-10

ID and timestamp are auto-insertions by the database when the other 4 fields are added.

The first thing to note is that a user can record multiple playings of the same scenario (scenid) on the same date (playdate) possibly with the same outcome (side = winner). Hence the need for the unique ID and timestamps for good measure.

Now, on their user page, I'm displaying their recorded play history in a <select><option>... list form with 2 buttons at the end - Delete Record and Go to Scenario

My script takes the scenid and after hitting a few other tables returns with something more user-friendly like:

  (playdate)   (from scenid)        (from side)
#########################################################
# 2010-03-10  Road to Berlin #1 -- Germany, Hungary won #
# 2010-03-10  Road to Berlin #1 -- Germany, Hungary won #
# 2010-03-10  Road to Berlin #1 -- Soviet Union won     #
#########################################################
     [Delete Record]              [Go To Scenario]

in HTML:

<select name="history" size=3>
  <option>2010-03-10  Road to Berlin #1 -- Germany, Hungary won</option>
  <option>2010-03-10  Road to Berlin #1 -- Germany, Hungary won</option>
  <option>2010-03-10  Road to Berlin #1 -- Soviet Union won</option>
</select>

Now, if you were to highlight the first record and click Go to Scenario there is enough information there for me to parse it and produce the exact scenario you want to see. However, if you were to select Delete Record there is not - I have the playdate and I can parse the scenid and side from what's listed, but in this example all three records would have the same result.

I appear to have painted myself into a corner. Does anyone have a suggestion as to how I can get some unique identifying data (ID and/or timestamp) to ride along on this form without showing it to the user?

PHP-only please, I must be NoScript compliant!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

您可以在选项上设置 value 属性,并使其包含数据的 ID (这是唯一的)

<select name="history" size=3>
  <option value="1">2010-03-10  Road to Berlin #1 -- Germany, Hungary won</option>
  <option value="2">2010-03-10  Road to Berlin #1 -- Germany, Hungary won</option>
  <option value="3">2010-03-10  Road to Berlin #1 -- Soviet Union won</option>
</select>

然后,在接收时已发布的数据,$_POST['history'] 将包含与用户选择的条目相对应的 ID

而且,由于此 ID 是唯一的,因此您可以毫无疑问地用来识别您的数据。

value 属性的内容设置后,会在提交表单时传递到服务器,但不会向用户显示。

当没有为选项设置值时,浏览器会在提交表单时将该选项的内容传递给服务器——这就是您所得到的。

作为旁注:与用户提交的所有内容一样,您必须检查 $_POST['history'] 收到的值是否有效、安全以及所有这些 - 它应该是一个整数,它应该是用户可以访问的值之一,...

You can set a value attribute on your options, and make it contain the ID (which is unique) of your data :

<select name="history" size=3>
  <option value="1">2010-03-10  Road to Berlin #1 -- Germany, Hungary won</option>
  <option value="2">2010-03-10  Road to Berlin #1 -- Germany, Hungary won</option>
  <option value="3">2010-03-10  Road to Berlin #1 -- Soviet Union won</option>
</select>

Then, when receiving the data that's been posted, $_POST['history'] will contain the ID that correspond to the entry choosen by the user.

And, as this ID is unique, you can use to identify, without any doubt, your data.

The content of the value attribute, when set, is passed to the server when the form is submitted -- it's not displayed to the user.

When no value is set for an option, the browser will pass the content of that option to the server, when the form is submitted -- which is what you were getting.

As a sidenote : as with everything submitted from a user, you must check that the value received for $_POST['history'] is valid, safe, and all that -- it should be an integer, it should be one one the values the user can access, ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文