一.准备
1.php
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<title>表单提交</title>
</head>
<body>
<form action='1.php' method='post'>
<table>
<tr>
<td>title:</td>
<td><input type='text' name='title'></td>
</tr>
<tr>
<td>content:</td>
<td><input type='text' name='content'></td>
</tr>
<tr>
<td></td>
<td><input type='submit' value='提交表单'></td>
</tr>
</table>
</form>
</body>
</html>
<?php
$link = mysqli_connect('localhost','root','123','test');
if (!$link) {
printf('Can not connect to MySQL Server. Errorcode: %s ', mysqli_connect_error());
exit;
}
mysqli_query($link,'set names utf8');
$sql='insert into message(title,content) values('.$_POST['title'].','.$_POST['content'].')';
$result = mysqli_query($link,$sql);
mysqli_free_result($result);
mysqli_close($link)
?>
在数据库中创建表message
create table message(
message_id int(5) unsigned not null auto_increment,
title varchar(100) not null,
content varchar(100) not null,
primary key(message_id)
)engine=myisam default charset=utf8;