php+html 表单提交数据保存到mysql中

html form端代码

















用户名
密码
手机号





php端代码

//声明变量并接受form表单发送过来的数据
$username = $_POST['username']; 
$password = $_POST['password'];
$phone = $_POST['phone'];

//字符串拼接,打印输出
echo $username."
".$password."
".$phone."
";

//连接数据库
$con = mysql_connect("localhost","root","");
if($con){
echo "
连接成功"."
";
} else{
echo "
连接失败".mysql_error();
}
//选择数据库
mysql_select_db("html");
//设置mysql字符编码
mysql_query("set names utf8;");
//insert语句
$insert = "insert into user (username,password,phone) values ('$username','$password','$phone')";
/*$res_insert = mysql_query($insert);
if($res_insert){
echo "
插入成功";
} else {
echo "
插入失败";
}*/
//update语句
$update = "update user set username='$username',password='$password',phone='$phone' where id= 20";
//$res_update = mysql_query($update);
//select语句
$select = "select * from user";
$res_select = mysql_query($select);
echo "

";
while($row = mysql_fetch_row($res_select)){
echo "";
}
echo "
idusernamepasswordphone
".$row[0]."".$row[1]."".$row[2]."".$row[3]."
";
?>

你可能感兴趣的:(HTML,php,mysql)