// 家 index.php
creat.php使用此代码发送数据到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();
如何使它在发送数据时立即转换为index.php
主页位于http://localhost/mysite/index.php
<form>属性中的标记action指定将从表单接收和处理数据的处理程序。那些。<form action="index.php" method="post">将重定向到 index.php 以及最终$_POST以数组形式出现的表单数据。