您的位置:

phpmysql登录注册程序,php实现登录注册

本文目录一览:

php mysql用户注册

?php

if($_POST){

extract($_POST);

if(trim($username)==''){ //提交后检测

echo '用户名不能为空';

exit();

}

if(trim(password1)!='' password1==password2){

$password = md5($password1);

}else{

echo '两次输入的密码不一至!';

exit();

}

mysql_query("insert into 表 (username,password) values('$username','$password')");

}

?

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""

html xmlns=""

head

meta http-equiv="Content-Type" content="text/html; charset=utf-8" /

titletest/title

/head

script type="text/javascript"

function $(id){return document.getElementById(id).value;}

function checkForm(){ //提交前检测

if($('username')==''){

alert('用户名不能为空!');

return false;

}

if($('username').length 11){

alert('用户名不超过11位');

return false;

}

if($('password1')==''){

alert('密码不能为空!');

return false;

}

if($('password1')!=$('password2')){

alert('两次输入的密码不一至!');

return false;

}

return true;

}

/script

body

form id="form1" name="form1" method="post" action="" onsubmit="return checkForm();"

p

用户名:

input type="text" name="username" id="username" onkeyup="value=value.replace(/[\W]/g,'') " onbeforepaste="value=value.replace(/[\W]/g,'')"/

/p

p

密码:

input type="text" name="password1" id="password1" /

/p

p重复密码:

input type="text" name="password2" id="password2" /

/p

p

input type="submit" name="button" id="button" value="提交" /

/p

/form

/body

/html

PHP+MySql注册登录

你看一下我这个能不能明白,我也是学这个的,有时间可以一起探讨一下,我QQ:772965552,问题:13796730936

先建数据库

CREATE DATABASE yonghudenglu;

USE yonghudenglu;

CREATE TABLE yonghudenglu (

id int(10) unsigned,

name varchar(50),

xingbie varchar(50),

mima varchar(50),

);

注册页面:

?php

//连接数据库

$link = mysql_connect('localhost', 'root', '123456');

//判断连接是否成功

if (!$link)

{

die('Could not connect: ' . mysql_error());

}

//选择数据库

mysql_select_db("yonghudenglu");

//判断姓名是否为空

if (!empty($_POST['name']))

{

if (!empty($_POST['xingbie']))

{

if (!empty($_POST['mima']))

{

$name=($_POST['name']);

$xingbie=($_POST['xingbie']);

$mima=($_POST['mima']);

$xinmima=($_POST['xinmima']);

$query="select name,xingbie from yonghudenglu where name='$name' and xingbie='$xingbie'";

$result=mysql_query($query);

$num_rows = mysql_num_rows($result);

if ($num_rows0)

{

echo "您输入的用户名已经有人注册了,请重新输入!";

echo "script language=\"JavaScript\"\r\n";

echo " alert(\"您输入的用户名已经有人注册,请重新输入!\");\r\n";

echo " history.back();\r\n";

echo "/script";

exit;

}

else

{

if ($mima==$xinmima)

{

$sql1="insert into yonghudenglu (name,xingbie,mima) values('$name','$xingbie','$mima');";

mysql_query($sql1);

mysql_query("commit");

echo "script language=\"JavaScript\"\r\n";

echo " alert(\"恭喜您注册成功!\");\r\n";

echo " location.replace(\"10.htm\");\r\n"; // 自己修改网址

echo "/script";

exit;

}

else

{

#echo "您没有输入密码,请重新输入!";

echo "script language=\"JavaScript\"\r\n";

echo " alert(\"您输入的两次密码不一样,请重新输入!\");\r\n";

echo " history.back();\r\n";

echo "/script";

exit;

}

}

}

else

{

#echo "您没有输入密码,请重新输入!";

echo "script language=\"JavaScript\"\r\n";

echo " alert(\"您没有输入密码,请重新输入!\");\r\n";

echo " history.back();\r\n";

echo "/script";

exit;

}

}

else

{

echo "script language=\"JavaScript\"\r\n";

echo " alert(\"您没有选择性别,请重新选择!\");\r\n";

echo " history.back();\r\n";

echo "/script";

exit;

}

}

else

{

echo "script language=\"JavaScript\"\r\n";

echo " alert(\"您没有输入姓名,请重新输入!\");\r\n";

echo " history.back();\r\n";

echo "/script";

exit;

}

?

登陆页面:

?php

$link = mysql_connect('localhost', 'root', '123456');

if (!$link)

{

die('Could not connect: ' . mysql_error());

}

mysql_select_db("yonghudenglu");

if (!empty($_POST['name']))

{

if (!empty($_POST['mima']))

{

$name=($_POST['name']);

$mima=($_POST['mima']);

$quer="select name,mima from yonghudenglu where name='$name'";

$result=mysql_query($quer);

$num_rows = mysql_num_rows($result);

$row = mysql_fetch_array($result, MYSQL_ASSOC);

if ($num_rows0)

{

$mima1=$row["mima"];

if ($mima==$mima1)

{

echo "script language=\"JavaScript\"\r\n";

echo " alert(\"登陆成功\");\r\n";

echo " location.replace(\"12.html\");\r\n"; // 自己修改网址

echo "/script";

exit;

}

else

{

echo "script language=\"JavaScript\"\r\n";

echo " alert(\"您输入的密码不正确!请重新输入!\");\r\n";

echo " history.back();\r\n";

echo "/script";

exit;

}

}

else

{

echo "script language=\"JavaScript\"\r\n";

echo " alert(\"您还没有注册,请先注册!\");\r\n";

echo " history.back();\r\n";

echo "/script";

exit;

}

}

else

{

#echo "您没有输入密码,请重新输入!";

echo "script language=\"JavaScript\"\r\n";

echo " alert(\"您没有输入密码,请重新输入!\");\r\n";

echo " history.back();\r\n";

echo "/script";

exit;

}

}

else

{

echo "script language=\"JavaScript\"\r\n";

echo " alert(\"您没有输入姓名,请重新输入!\");\r\n";

echo " history.back();\r\n";

echo "/script";

exit;

}

?

不会就加我啊,哈哈

怎么用php程序将登录或者注册信息写进数据库(mysql)?

$query="select * from reg where username='$username' and pwd='$pwd'";

将该语句这样写:$query = sprintf("select * from reg where username=%s and pwd=%s ", $username, $pwd);

php+mysql怎么做登录注册

首先得到提交的数据

链接数据库,查询数据库,查询username 和pwd

提交的username 和 pwd  跟数据库查询的username 和pwd做对比,

都相等那就是登陆成功

?php

mysql_connect('localhost','root','123');

mysql_select_db('lx');

mysql_query("SET CHARACTER SET utf8");

mysql_query("SET NAMES utf8");

//数据库lx 表user  字段id username  pwd

//用md5加密,可以自己试试    

    

if(isset($_POST['user'])$_POST['tijiao'] == 'success'){

    $query = mysql_query("select pwd from user where username = '".$_POST['user']."'");

    $num = mysql_num_rows($query);

    if($num  0 ){

        while($info = mysql_fetch_array($query)){

                if($info['pwd'] == md5($_POST['pwd'])){

                        echo '登陆成功';

                    }else{

                        echo '登陆失败';    

                    }

            }

    

    }else{

        

            echo '登陆失败';

        }

}

?

form action="" method="get"/

table border="0" cellspacing="0" cellpadding="0" 

      tr

        td class="fieldKey" width="30%"用户名:/td

        td class="fieldValue" width="100%"input type="text" name="user" //td

      /tr

      trtd height="10"/td/tr

      tr

        td class="fieldKey"密码:/td

        td class="fieldValue"input type="password" name="pwd" //td

      /tr

    /table

    input type="hidden" name="tijiao" value="success" /

     input type="submit" value="登陆"/

/form