简体   繁体   English

在 PHP 中从多个问题单选表单中插入多行

[英]Inserting multiple rows from multiple question radio form in PHP

I have a form to determine the user's personality.我有一个表格来确定用户的个性。 So each question (there are 25) has 4 possible answers to choose from:所以每个问题(有 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>

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.数据库中的下一行还应包含姓名、姓氏,然后是所有 25 个问题的下一个问题的选择。

My table users in the database only has 3 columns namely: name , surname , q我在数据库中的表users只有 3 列,即: namesurnameq

I am very new to PHP and tried some previous questions but none worked for my particular scenario.我对 PHP 非常陌生,并尝试了一些以前的问题,但没有一个适用于我的特定场景。

I assume you are working fully with PHP, so no JavaScript or Ajax involved.我假设您完全使用 PHP,因此不涉及 JavaScript 或 Ajax。

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 .target.php中,您需要从$_POST中读取数据。 In your case, it must be something like $_POST['name'] .在您的情况下,它必须类似于$_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.请将此答案视为一个最小问题,因为您需要进行进一步检查,例如安全检查、防止 SQL 注入和整体数据验证。

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

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