I want to store some data from my input form.
<?php
include_once"function.php";
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
$email = $_POST['email'];
$items = $_POST['items'];
$tecnology = $_POST['tecnology'];
$range = $_POST['price-range'];
if (empty($name) || empty($email) || empty($items) || empty($tecnology) || empty($range)) {
echo "Please fill all the fields";
} else {
$data = sprintf("%s %s %s %s %s", $name, $email, $items, $tecnology, $range);
put($data);
echo $data;
}
}
?>
function.php file code is
<?php
function put($data){
$filename = "E:/xampp/htdocs/cookies/database.text";
if (is_readable($filename) && is_writable($filename)){
$fp = fopen($filename, 'a');
file_put_contents($filename, serialize($data));
fclose($fp);
}else {
echo "Error" . "<br/>";
}
}
This code doesn’t store data in my txt file. But this $data
variable stored the whole input.
Recognized by PHP Collective
New contributor
Mijanur Rahman Mathin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1