1.添加页面
<h1>添加数据</h1>
<form action="chuli.php" method="post">
<div>代号:<input type="text" name="code" /></div>
<div>名称:<input type="text" name="name" /></div>
<input type="submit" value="添加" />
</form>
2.处理页面
(1)造PDO对象
$dsn = "mysql:dbname=mydb;host=localhost";
$pdo = new PDO($dsn,"root","123"); (2)预处理语句
$sql = "insert into nation values(:code,:name)";
$stm = $pdo->prepare($sql); (3)执行
$stm->execute($_POST);