I'm trying to find my error in the following piece of code. First the user will have to fill out the following form. Within this php, there is a GET variable named 'code' (example: feedback_form.php?code=ABC):
<?php
session_start();
include ("feedback_form_entry.php");
if (!isset($_SESSION["feedback_ok"])) {
header('Location: login_error.php');
exit;
}
?>
<!doctype html>
<html>
<head>
</head>
<body>
<form method="post" id="contact_form" action="feedback_form_entry.php">
<textarea type="text" name="nps_question_2" rows="4" spellcheck="false" placeholder="What was the reason you gave us this rating?"></textarea>
<textarea type="text" name="nps_question_3" rows="4" spellcheck="false" placeholder="What can we do to improve your experience?"></textarea>
<input class="button" type="submit" name ="send_feedback" value="SEND FEEDBACK">
</form>
</body>
</html>
Then the following script should follow (feedback_form_entry.php):
<?php
$nps = "";
$nps_question_2 = "";
$nps_question_3 = "";
function test_input($data) {
return htmlspecialchars(stripslashes(trim($data)));
}
if (isset($_POST["send_feedback"])) {
$nps_question_2 = test_input($_POST["nps_question_2"]);
include("db_connect.php");
$nps_question_2_update = $con->prepare("UPDATE codes SET `nps_question_2`=? WHERE `code`=" . $_GET["code"]);
$nps_question_2_update->bind_param("s", $nps_question_2);
$nps_question_2_update->execute();
$nps_question_2_update->close();
header('Location: feedback_form_success.php');
$con->close();
}
?>
Now I will get the following error message:
Notice: Undefined index: code in C:\xampp\htdocs\tours\feedback_form_entry.php on line 15
and I can't really find out, where the problem is. I tried defining the GET variable as $code, but it just won't work.
Thanks in advance for any suggestion!