I don't know if what I'm trying to do is achievable / plausible but I'll ask anyway:
I am building a survey type website and am looking at storing the responses in a MySQL DB. Each response / text field will be a record
The current page that I'm working on has two elements (Answer1 and Answer2).
How can I get the submit to add each answer as a separate line in my DB? eg, 2 separate records, with different text stored in the responsetext field?
I have the below (obviously changed for security reasons), which adds one record, but of the element that I specify:
$conn = new mysqli($dbhost, $dbuser, $dbpass,$dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$stmt = $conn->prepare("INSERT INTO responses (qkey,rtext)
VALUES ('".$_POST["1"]."','".$_POST["Q1Answer"]."')");
$Q1Answer = $_POST["Q1Answer"];
$stmt->bind_param("s", $Q1Answer);
$stmt->execute();
$stmt->close();
$conn->close();
I imagine I could loop through all the elements and add them one by one? Is this possible on the submit action / post?
I have searched here but can't find anything that has been able to help...