php根据表单数据添加到数据库
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h2>get请求</h2>
//选择提交地址
<form action="http://localhost/day2(http)/get.php" method="get">
<input type="text" name="username">
<input type="text" name="password">
<input type="submit" value="提交">
</form>
<h2>post请求</h2>
<form action="http://localhost/day2(http)/post.php" method="post">
<input type="text" name="username">
<input type="text" name="password">
<input type="submit" value="提交">
</form>
</body>
</html>
<?php
header('content-type:text/html;charset=utf-8');
$username=$_POST['username'];
$password=$_POST['password'];
mysql_connect('localhost','root','root');
mysql_select_db('gz2006');
$sql="INSERT INTO user VALUE('$username','$password')";
$isSuccess=mysql_query($sql);
if($isSuccess==1){
echo '插入成功';
}
mysql_close();
?>