// home index.php

creat.php send data using this code to index.php

 <!doctype html> <html lang="en"> <head> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> </head> <body> <div class="container"> <div class="row"> <div class="col-md-12"> <h1>Create Task</h1> <form action="store.php" method="post"> <div class="form-group"> <input type="text" class="form-control" name="title"> </div> <div class="form-group"> <textarea name="content" class="form-control"></textarea> </div> <div class="form-group"> <button class="btn btn-success" type="submit">Submit</button> </div> </form> </div> </div> </div> </body> </html> <?php $pdo = new PDO("mysql:host=localhost;dbname=mysite","root",""); $sql = 'INSERT INTO dates(title, content) VALUES (:title, :content)'; $statement = $pdo->prepare($sql); $statement->bindParam(":title",$_POST['title']); $statement->bindParam(":content",$_POST['content']); $result = $statement->execute(); header("Location: /");exit(); 

how to make it so that when sending data, immediately transferred to index.php

the main page is located at http://localhost/mysite/index.php

1 answer 1

The <form> in the action attribute specifies a handler that will receive and process data from the form. Those. <form action="index.php" method="post"> redirect to index.php along with the form data that will fall into the $_POST array.