Я новичок в php и пытаюсь создать форму, чьи входы добавляются в CSV-файл, но я не получаю никаких выходных данных или ошибок ........................................................................................................................................................................................................................................................................................
код:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h3>Feedback Form</h3>
<div class="container">
<form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<label for="name">Name</label>
<input type="text" id="name" name="name" placeholder="Your Name.." required>
<label for="desg">Designation</label>
<input type="text" id="desg" name="desg" placeholder="Your Designation" required>
<label for="rating">Rating</label><br/>
<input type="radio" name="rating" id="r1" value="excellent" checked> excellent<br>
<input type="radio" name="rating" id="r2" value="good"> good<br>
<input type="radio" name="rating" id ="r3" value="needsimprovement" >needs improvement <br>
<input type="radio" name="rating" id="r4" value="bad"> bad
<br/><br/>
<label for="dept">Department</label>
<input type="text" id="dept" name="dept" placeholder=" Dept" required>
<label for="comments">Comments</label>
<textarea id="comment" name="comment" placeholder="Write comments here" style="height:200px" required></textarea>
<input type="submit" value="submit" id="btn" >
</form>
</div>
<?php
echo "datapage";
$nameErr = $emailErr = $desgErr = $ratingErr = "";
$name = $desg = $rating = $comment = $rating = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = ($_POST["name"]);
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
}
if (empty($_POST["desg"])) {
$emailErr = "desgn is required";
} else {
$desg = ($_POST["desg"]);
if (!preg_match("/^[a-zA-Z ]*$/",$desg)) {
$nameErr = "Only letters and white space allowed";
}
}
if (empty($_POST["rating"])) {
$rating = "";
} else {
$rating = ($_POST["rating"]);
if (!preg_match("/^[a-zA-Z ]*$/",$desg)) {
$nameErr = "invalid";
}
}
if (empty($_POST["comment"])) {
$comment = "";
} else {
$comment = ($_POST["comment"]);
}
//$array = array($name,$desg,$rating,$comment);
$fp = fopen('data.csv', 'a+');
$no_rows = count(file("data.csv"));
$array1 = array(
'sr_no' => $no_rows,
'name' => $name,
'desg' => $desg,
'rating' => $rating,
'comments' => $comment
);
fputcsv($fp, $array1);
fclose($fp);
$error = '<label class="text-success">form submitted</label>';
}
/*function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
*/
}
?>
</body>
</html>