1 Star 0 Fork 0

李晓敏 / php

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
adduser.php 2.27 KB
一键复制 编辑 原始数据 按行查看 历史
李晓敏 提交于 2024-05-08 08:25 . 0508
<!DOCTYPE html>
<?php
$frist=!count($_POST);
?>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
if($frist){
//第一次访问渲染页面
?>
<h1>添加用户</h1>
<form action="adduser.php" method="post" enctype="multipart/form-data">
账户:<input type="text" name="username"/><br/>
密码:<input type="password" name="upwd"/><br/>
性别:<select name="sex">
<option></option>
<option></option>
</select>
<br/>
年龄:
<select name="age">
<?php
for($index=18;$index<=100;$index++){
echo "<option>$index</option>";
}
?>
</select>
<br/>
头像:<input type="file" name="myimg"/><br/>
<input type="submit" value="确定"/>
<input type="reset" value="取消"/>
</form>
<?php
}else{
//不是第一次访问的话 就处理数据
$name=$_POST["username"];
$upwd=$_POST["upwd"];
$age=$_POST["age"];
$sex=$_POST["sex"];
$newImgPath="img/".time()."_".$_FILES["myimg"]["name"];
move_uploaded_file($_FILES["myimg"]["tmp_name"], $newImgPath);
$pic=$newImgPath;
$hostname="127.0.0.1";
$username="root";
$password="123456";
$database="myshop";
$connect=mysqli_connect($hostname, $username, $password, $database);
//设置连接的字符集
mysqli_set_charset($connect, "utf-8");
if($connect){
$sqlstring="insert into userinfos(username,upasswd,pic,sex,age)"
. " values('${name}','${upwd}','${pic}','${sex}',${age})";
$result=mysqli_query($connect, $sqlstring);
if($result){
echo "<script>alert('添加成功!');"
. "location='mysql001.php';</script>";
}else{
echo "添加失败";
}
}
mysqli_close($connect);
}
?>
<?php
// put your code here
?>
</body>
</html>
1
https://gitee.com/li-iaoin/php.git
git@gitee.com:li-iaoin/php.git
li-iaoin
php
php
master

搜索帮助