html form端代码
<div id="content">
<form method="post" action="php/regist.php" ><table >
<tr>
<th>用户名</th>
<td><input name="username" value="" placeholder="这里输入文字" type="text" /></td>
</tr>
<tr>
<th>密码</th>
<td><input name="password" value="" type="password" placeholder="请设置登录密码" /></td>
</tr>
<tr>
<th>手机号</th>
<td>
<input name="phone" value="" type="text" placeholder="可用于登录和找回密码"/>
</td>
</tr>
<tr>
<th></th><td><input type="submit" value="注册" name="reg" id="tijiao" /></td>
</tr>
</table>
</form>
</div>
php端代码
<?php
//声明变量并接受form表单发送过来的数据
$username = $_POST['username'];
$password = $_POST['password'];
$phone = $_POST['phone'];
//字符串拼接,打印输出
echo $username."<br/>".$password."<br/>".$phone."<br/>";
//连接数据库
$con = mysql_connect("localhost","root","");
if($con){
echo "<br/>连接成功"."<br/>";
} else{
echo "<br/>连接失败".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 "<br/>插入成功";
} else {
echo "<br/>插入失败";
}*/
//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 "<table width=600 align='center'><tr><td>id</td><td>username</td><td>password</td><td>phone</td></tr>";
while($row = mysql_fetch_row($res_select)){
echo "<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td><td>".$row[3]."</td></tr>";
}
echo "</table>";
?>