- Joined
- Feb 12, 2025
- Messages
- 2
- Reaction score
- 0
Afternoon all,
I've been searching online for an answer to this.
Requirement:
I want to have a webpage with a form on it.
The data from this form once the submit button is pressed it populates a csv (data.csv) on the server with the website is hosted.
The webpage with the form on it will be called: input.php
I have found this code.
The php page will be called process.php:
the csv has only two columns
id_number
first_name
When the Submit button is pressed it goes to the process page with these errors.
Warning: Undefined array key "id_number" in C:\xampp\htdocs\testsite\process.php on line 5
Warning: Undefined array key "first_name" in C:\xampp\htdocs\testsite\process.php on line 5
But still nothing is written to the data.csv
Could someone please help.
Thank you in advance,
I've been searching online for an answer to this.
Requirement:
I want to have a webpage with a form on it.
The data from this form once the submit button is pressed it populates a csv (data.csv) on the server with the website is hosted.
The webpage with the form on it will be called: input.php
I have found this code.
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link rel="stylesheet" href="./css/main.css" />
<script src="./js/app.js"></script>
</head>
<body>
<form name="xyz_form" action="process.php" method="get">
<section class="border-bottom">
<div class="content">
<h3>ID Number</h3>
<div class="form-control-group">
<div class="form-control form-control-number">
<input type="number" id="id_number">
</div>
</div>
<h3>First Name</h3>
<div class="form-control-group">
<div class="form-control form-control-text">
<input type="text" id="first_name">
</div>
</div>
</div><!--.content-->
<section class="data-capture-buttons one-buttons">
<div class="content">
<input type="submit" value="Submit" onClick="javascript:addToCSVFile()">
</div>
</section><!--.data-capture-buttons-->
</body>
</html>
The php page will be called process.php:
PHP:
<?php
$keys = array('id_number','first_name');
$csv_line = array();
foreach($keys as $key){
array_push($csv_line,'' . $_GET[$key]);
}
$fname = 'data.csv';
$csv_line = implode(',',$csv_line);
if(!file_exists($fname)){$csv_line = "\r\n" . $csv_line;}
$fcon = fopen($fname,'a');
$fcontent = $csv_line;
fwrite($fcon,$csv_line);
fclose($fcon);
// echo file_get_contents($fname);
?>
the csv has only two columns
id_number
first_name
When the Submit button is pressed it goes to the process page with these errors.
Warning: Undefined array key "id_number" in C:\xampp\htdocs\testsite\process.php on line 5
Warning: Undefined array key "first_name" in C:\xampp\htdocs\testsite\process.php on line 5
But still nothing is written to the data.csv
Could someone please help.
Thank you in advance,