在PHP中插入多个问题无线电形式的多行

发布于 2025-02-03 16:40:33 字数 1945 浏览 2 评论 0原文

我有一个表格来确定用户的个性。因此,每个问题(有25个)都有4个可能的答案供您选择:

<form method="post">

  <div>
    <label for="name"></label>
    <input name="name" id="name" placeholder="Name">
  </div>

  <div>
    <label for="surname"></label>
    <input name="surname" id="surname" placeholder="Surname">
  </div>

  <br>

  <div>
    <label for="q1">Question 1</label><br>
    <input type="radio" name="q1" id="q1" value="S"> q1c1 <br>
    <input type="radio" name="q1" id="q1" value="D"> q1c2 <br>
    <input type="radio" name="q1" id="q1" value="K"> q1c3 <br>
    <input type="radio" name="q1" id="q1" value="I"> q1c4 <br>
  </div>

  <br>

  <div>
    <label for="q2">Question 2</label><br>
    <input type="radio" name="q2" id="q2" value="D"> q2c1 <br>
    <input type="radio" name="q2" id="q2" value="K"> q2c2 <br>
    <input type="radio" name="q2" id="q2" value="I"> q2c3 <br>
    <input type="radio" name="q2" id="q2" value="S"> q2c4 <br>
  </div>

  <br>

  <div>
    <label for="q3">Question 3</label><br>
    <input type="radio" name="q3" id="q3" value="S"> q3c1 <br>
    <input type="radio" name="q3" id="q3" value="I"> q3c2 <br>
    <input type="radio" name="q3" id="q3" value="D"> q3c3 <br>
    <input type="radio" name="q3" id="q3" value="K"> q3c4 <br>
  </div>

<br><br>
  <button>Submit</button>

</form>

我需要在一行中插入问题,姓氏和选择问题的选择。数据库中的下一行还应包含名称,姓氏,然后在所有25个问题上选择下一个问题的选择。

我的表用户在数据库中只有3列,即:name姓氏q

我非常新鲜PHP并尝试过一些以前的问题,但没有一个针对我的特定情况。

I have a form to determine the user's personality. So each question (there are 25) has 4 possible answers to choose from:

<form method="post">

  <div>
    <label for="name"></label>
    <input name="name" id="name" placeholder="Name">
  </div>

  <div>
    <label for="surname"></label>
    <input name="surname" id="surname" placeholder="Surname">
  </div>

  <br>

  <div>
    <label for="q1">Question 1</label><br>
    <input type="radio" name="q1" id="q1" value="S"> q1c1 <br>
    <input type="radio" name="q1" id="q1" value="D"> q1c2 <br>
    <input type="radio" name="q1" id="q1" value="K"> q1c3 <br>
    <input type="radio" name="q1" id="q1" value="I"> q1c4 <br>
  </div>

  <br>

  <div>
    <label for="q2">Question 2</label><br>
    <input type="radio" name="q2" id="q2" value="D"> q2c1 <br>
    <input type="radio" name="q2" id="q2" value="K"> q2c2 <br>
    <input type="radio" name="q2" id="q2" value="I"> q2c3 <br>
    <input type="radio" name="q2" id="q2" value="S"> q2c4 <br>
  </div>

  <br>

  <div>
    <label for="q3">Question 3</label><br>
    <input type="radio" name="q3" id="q3" value="S"> q3c1 <br>
    <input type="radio" name="q3" id="q3" value="I"> q3c2 <br>
    <input type="radio" name="q3" id="q3" value="D"> q3c3 <br>
    <input type="radio" name="q3" id="q3" value="K"> q3c4 <br>
  </div>

<br><br>
  <button>Submit</button>

</form>

I need to insert the name, surname, and the selection of the question in one line. The next row in the database should also contain the name, surname, and then the next question's selection for all 25 questions.

My table users in the database only has 3 columns namely: name, surname, q

I am very new to PHP and tried some previous questions but none worked for my particular scenario.

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

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

发布评论

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

评论(1

凉栀 2025-02-10 16:40:33

我认为您正在与PHP完全合作,因此不涉及JavaScript或Ajax。

首先,您需要指定请求应发送的何处:

<form method="post" action="https://example.org/target.php">

target.php中,您需要从$ _ POST中读取数据。在您的情况下,它一定是$ _ post ['name']

从那里开始,您可以使用数据做任何您想做的事情。

请将此答案视为最小问题,因为您需要进行进一步的检查,例如安全检查,防止SQL注射和整体数据验证。

I assume you are working fully with PHP, so no JavaScript or Ajax involved.

first of all you need to specify where your request should send:

<form method="post" action="https://example.org/target.php">

in target.php, you need to read data out of $_POST. In your case, it must be something like $_POST['name'].

From there on, you can do whatever you want with the data.

Please consider this answer as a minimal question as you need to do further checks, such as security checks, prevent SQL injections and overall data validation.

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