你这个需求为了更好的用户体验,用ajax无刷新好点吧。代码也很简单,去网上搜索一下。
解决方案 »
- 江湖求救:小弟安装LAMP平台遇到一点问题:Fatal error: Class 'mysqli' not found
- 使用Installshield 2010 premier,生成错误,错误ID:7108 求高手指点!!!
- 大家谁用过eyeOS 2.x的进来贴吧
- 很容易拿到的分,投票程序处理上遇到问题求解 !!!
- 如何使每行显示三列???
- 大家平时都用什么写代码?问下关于sublime text 2和netbeans的问题。
- preg_replace()错误
- 在下的网站两个版本,不知取舍?
- 有用php做过wap开发的吗?小弟有一个问题!
- Zend Studio安装:Could not open key
- wamp下运行php错误问题,急求解决
- PHP不支持私有类吧?
$_POST获取用户名。在执行SQL查询。
/*注册文件
* $Author: 陈义
* $Id: regist.php 2013-12-17 21:07 陈义
*/
//检查session是否存在。
include('check_session.php');
include('head.php');
if(isset($_SESSION['id']) &&isset($_SESSION['pass'])){
// if(isset($_SESSION['id'])==true &&isset($_SESSION['pass'])==true){
exit("当前已有一个登陆在线的用户<span class=online_user>".$_SESSION['id']."</span>需要再<a href=regist.php>注册</a>请先<a href=index.php?act=out>退出。</a>否则请<a href=javascript: onclick=history.go(-1);>返回</a>");
}define('cy','cychat');
include('config.php');$name=isset($_POST['name']) ? $_POST['name']:null;
$password=isset($_POST['password']) ? $_POST['password']:null;
$addess=isset($_POST['addess']) ? $_POST['addess']:null;
$age=isset($_POST['age']) ? $_POST['age']:null;
$name_md5=md5($name);//给用户名add 一个 md5值////////////////接收用户上传的头像文件///////////////////////////
error_reporting(0);
$upfilepath="image/userimage/";
$file_houzhui='';
if($_FILES["userimage"]["type"] == "image/gif"){
$file_houzhui=".gif";
}if($_FILES["userimage"]["type"] == "image/jpeg"){
$file_houzhui=".jpg";
}if($_FILES["userimage"]["type"] == "image/png"){
$file_houzhui=".png";
}switch ($_FILES["userimage"]["error"])
{
case 1:
echo "上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值";
break;
case 2:
echo "上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值";
break;
case 3:
echo "文件只有部分被上传.";
break;
case 4:
echo "你没有上传图像。";
break;
case 6:
echo "找不到临时文件夹.";
break;
case 7:
echo "文件写入失败.";
break;
} move_uploaded_file($_FILES["userimage"]["tmp_name"],$upfilepath.$_FILES["userimage"]["name"]);//从server 移动用户上传文件到新的路径
rename($upfilepath.$_FILES["userimage"]["name"] ,$upfilepath.'tmp'.$name.$file_houzhui);//将客户上传的文件更名为一个临时的文件$source_filename=$upfilepath.'tmp'.$name.$file_houzhui;///////////////////////调整用户上传的图片大小///////////////$filetype=mime_content_type($source_filename);//获取图片的类型。mime_content_type 函数要在php.ini打开 fileinfo选项
//echo 'the file type is'.$filetype;
list($width, $height) = getimagesize($source_filename);//获取原图片的大小//如果文件的宽度和高度都小于120就把临时文件改名为正式的文件,
if($width <= 120 && $height <= 120){
rename($upfilepath.'tmp'.$name.$file_houzhui,$upfilepath.$name.$file_houzhui);
}
//判断图片的width and height 大于120 就缩小为 120*120 的新图片
if($width > 120 || $heitht > 120){
$new_width = 120;
$new_height = 120;
$image_p = imagecreatetruecolor($new_width, $new_height);// 新建一个真色彩的文件
//// 重新取样,新建一个和用户上传同类型的文件
//判断用户上传的是那种类型图片
if($filetype == "image/gif"){
$image = imagecreatefromgif($source_filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);//copy 源图像到新建的真色彩文件。
imagegif($image_p,$upfilepath.$name.$file_houzhui);//保存图片到新地址,并且重新更名
}
//判断用户上传的是那种类型图片
if($filetype == "image/jpeg"){
$image = imagecreatefromjpeg($source_filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);//copy 源图像到新建的真色彩文件。
imagejpeg($image_p,$upfilepath.$name.$file_houzhui, 80);//保存图片到新地址,并且重新更名
}
//判断用户上传的是那种类型图片
if($filetype == "image/png"){
$image = imagecreatefrompng($source_filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);//copy 源图像到新建的真色彩文件。
imagepng($image_p,$upfilepath.$name.$file_houzhui);//保存图片到新地址,并且重新更名
} imagedestroy ($image);//销毁图片占用的内存
imagedestroy ($image_p);//销毁图片占用的内存
unlink($source_filename);//del 用户上传的原图片,这行很重要!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
//*//////////////////////////////////////$\
$useruploadimageaddess="";//用于插入数据库的变量//如果上传的不是图像文件或者没有上传文件
if($filetype != "image/png" && $filetype != "image/gif" && $filetype != "image/jpeg"){
$useruploadimageaddess='noaddess';
}else{
$useruploadimageaddess=$upfilepath.$name.$file_houzhui;//用于插入数据库的变量
}
///////////////////////////////////////////////////////
$sql = "INSERT INTO user( `user`,user_md5, `password`, `addess`, `age`,`userImage`,`regist_date`) VALUES ('$name','$name_md5','$password','$addess',$age,'$useruploadimageaddess',now())";
/////////////////////////////
/////////////////////////////
//检查是否有用户已经注册
$inquiry_username = mysql_query("SELECT user FROM user WHERE user='$name'");
if(mysql_num_rows($inquiry_username)>=1){
exit(' 对不起!!!<strong style=color:red>'.$name.'</strong>用户已经有人注册。');
}
//
if($name!=null && $password!=null && $addess!=null && $age!=null){
if(mysql_query($sql,$linkdatabase)){
exit("<p style=color:red><b>您已成功注册。请记住您的用户名和密码!用户名是$name 密码是$password 请<a href=\"login.php\">登录</a></p>");//如果注册成功就不输出下面的表单。
}else{
echo '注册失败,请重新注册';
}
}?><div class="regist">
<form method="post" enctype="multipart/form-data" action="regist.php">
<label for="name">用户名:</label>
<input class="regist_username" type="text" name="name" /> *<br/>
<label for="password">密 码:</label>
<input class="regist_password" type="password" name="password"/> *<br/>
<label for="addess">地 址:</label>
<input class="regist_addess"type="text" name="addess"/> *<br/>
<label for="age">年 龄:</label>
<input class="regist_age" type="text" name="age"/> *<br/>
<label for="userimage">头 像:</label>
<input type="file" name="userimage" value="userimage"><br/>
<input class="regist_regist" type="submit" value="注册"><br/>
<label for="info">带'*'号的必须要填写信息 </label>
</form>
</div><?php
include "footpage.php";//页脚
?>
$sql= 'select * from tbname where username ="'.$username.'"';
$result = mysql_query($sql);
$data = mysql_num_row($result);
if ($data){
echo "该用户名已存在";
}
$result = mysql_query($sql);
$data = mysql_num_rows($result);
if ($data){
echo "该用户名已存在";
}