i want to use if(isset($_POST['name'])) loop to test if user enter data so it will store it in database and if not so dont store it even when i refresh the page!!
i've tried to use if(isset($_POST['name'])) loop to test if user enter data so it will store it in database and if not so dont store it even when i refresh the page but doesnt work ! and when i refresh the page it store the last data that i've tried before!!
this is index.php :
<!DOCTYPE html>
<html>
<body>
<ul><?php
require "controller/database.php";
require "controller/users.php";
$user=new Users();
$user->insertUser($_POST['name'],$_POST['age'],$_POST['email']);
?></ul>
<form action="" method="POST">
<input type="text" name="name" required placeholder="Name"><br><br>
<input type="number" name="age" required placeholder="Age" ><br><br>
<input type="text" name="email" required placeholder="Email" ><br><br>
<button type="submit" name="insert" value="Add Data To Database"></button>
</form>
</body>
</html>
this is the users.php file :
<?php
class Users extends DB {
function insertUser($name,$age,$email){
$query = "INSERT INTO users (name, age, email )
VALUES ('$name', '$age', '$email')";
$res=$this->insert($query);
//return $this->select("SELECT * FROM `users`");
} }
i've tried to use if(isset($_POST['name'])) loop to test if user enter data so it will store it in database and if not so dont store it even when i refresh the page but doesnt work ! and when i refresh the page it store the last data that i've tried before!!
Please help!!
it show this error and store the data at the same time !
Notice: Undefined index: name in C:\xampp\htdocs\gestion de paie\index.php on line 10
Notice: Undefined index: age in C:\xampp\htdocs\gestion de paie\index.php on line 10
Notice: Undefined index: email in C:\xampp\htdocs\gestion de paie\index.php on line 10