溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

用戶注冊和用戶登錄簡單代碼

發(fā)布時間:2020-07-03 01:22:01 來源:網(wǎng)絡(luò) 閱讀:1400 作者:Im劉亞芳 欄目:web開發(fā)

index.php模塊(登錄模塊)

<table width="100%" border="0" cellpadding="0" cellspacing="0" class="border">

<form action="checklogin.php" method="post">

     <tr>

       <td width="29%" height="31" align="right" class="text12">用戶名:</td>

       <td align="left"><input name="username" type="text" size="15"></td>

     </tr>

     <tr>

       <td height="29" align="right" class="text12">密碼:</td>

       <td align="left"><input name="password" type="password" size="15"></td>

     </tr>

    <tr>

          </td>

     </tr>

     <tr>

       <td height="30" align="right">&nbsp;</td>

       <td align="left"><input type="submit" name="Submit" value="提  交">

           <input type="reset" name="Submit2" value="重  置"></td>

     </tr>

     <tr>

       <td height="27" align="right">&nbsp;</td>

       <td><a href="reg.php" class="text12">會員注冊</a></td>

     </tr>

 </form>

   </table>

reg.php模塊(注冊模塊)

<?

include("inc/conn.php");

?>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>會員注冊</title>

<link href="css.css" rel="stylesheet" type="text/css">

<style type="text/css">

<!--

.STYLE1 {color: #FF0000}

-->

</style>

</head>

<SCRIPT language=javascript>

function CheckPost()

{

if (myform.name.value.length=='')

{

alert("請?zhí)顚懶彰?);

myform.name.focus();

return false;

}


if (myform.password.value.length<2)

{

alert("請?zhí)顚懩拿艽a");

myform.password.focus();

return false;

}

if (myform.enpass.value.length<2)

{

alert("請?zhí)顚懩拇_認(rèn)密碼");

myform.enpass.focus();

return false;

}

if (myform.enpass.value!=myform.password.value)

{

alert("新密碼和確認(rèn)密碼不一致,請重新輸入");

myform.ennewpass.focus();

return false;

}

    myform.submit();

}

</SCRIPT>

<body>

   <td width="7" valign="top">&nbsp;</td>

   <td width="700" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">

     <tr>

       <td height="423" valign="top"><p>&nbsp;</p>

         <table width="93%" height="362" border="0" align="center" cellpadding="0" cellspacing="0" class="border">

         <tr>

           <td height="360" align="center"><table width="75%" border="0" cellpadding="0" cellspacing="0" class="border">

             <form action="save.php?act=add" method="post" name="myform">

               <tr>

                <tr>

                 <td height="33" align="right" class="text12">姓名:</td>

                 <td><input name="name" type="text" id="name">

                   <span class="STYLE1">*</span></td>

               </tr>

               <tr>

                 <td height="33" align="right" class="text12">學(xué)號:</td>

                 <td><input name="username" type="text" id="username">

                   <span class="STYLE1">*</span></td>

               </tr>


               <tr>

                 <td height="33" align="right" class="text12">密碼:</td>

                 <td><input name="password" type="password" id="password">

                   <span class="STYLE1">*</span></td>

               </tr>

               <tr>

                 <td height="33" align="right" class="text12">確認(rèn)密碼:</td>

                 <td><input name="enpass" type="password" id="enpass">

                   <span class="STYLE1">*</span></td>

               </tr>

                 <td height="33" align="right" class="text12">性別:</td>

                 <td><input name="sex" type="radio" value="男" checked>

                   男

                   <input type="radio" name="sex" value="女">

                   女</td>

               </tr>

               <tr>

                 <td height="33" align="right"><span class="text12">Email:</span></td>

                 <td><input name="email" type="text" id="email"></td>

               </tr>


               <tr>

                 <td height="33" align="right"><span class="text12">聯(lián)系QQ:</span></td>

                 <td><input name="qq" type="text" id="qq"></td>

               </tr>

               <tr>

                 <td width="35%" height="33">&nbsp;</td>

                 <td width="65%"><input type="button" name="Submit3" value="提  交" onClick="CheckPost()">

                     <input type="reset" name="Submit22" value="重  設(shè)"></td>

               </tr>

             </form>

           </table></td>

           </tr>

       </table></td>

       </tr>

   </table>

</td>

 </tr>

</table>

</body>

</html>

checklogin.php(檢查登錄模塊)

<?

session_start();

include("inc/conn.php");

$username=$_POST["username"];

$password=$_POST["password"];

  $sql="select * from user where username='$username' and password='$password'";

  $query=mysql_query($sql);

  if(mysql_num_rows($query)==0)

  {

    echo "<script>alert('請輸入正確的帳號密碼!');window.top.location.href='index.php'</script>";

   }

  else

   {

      $rs=mysql_fetch_assoc($query);

      $_SESSION["username"]=$username;

  echo "<script>alert('登陸成功');window.location.href='index.php'</script>";

   }

?>

save.php(保存數(shù)據(jù)模塊)

<?

include("inc/conn.php");

$username=$_POST["username"];

$password=$_POST["password"];

$sex=$_POST["sex"];

$email=$_POST["email"];

$qq=$_POST["qq"];


$sql="insert into user(username,password,sex,email,qq) values('$username','$password','$sex','$email','$qq')";

$query=mysql_query($sql);

if ($sql){echo "<script>alert('注冊成功,請登錄!'); window.location.href='index.php';</script>";}

?>

inc/conn.php數(shù)據(jù)庫連接模塊

<?

//ini_set("error_reporting","E_ALL & ~E_NOTICE");

$conn=mysql_connect ("localhost", "root", "") or die("沒有連接上啊!");

//127.0.0.1是MySql IP,root是帳號,如果有密碼請?zhí)顚懺?"中

mysql_select_db("reg") or die("沒有連接上"); //guestbook是數(shù)據(jù)庫名

mysql_query("set names gb2312");

?>

整理中出現(xiàn)的問題:

數(shù)據(jù)庫中中文出現(xiàn)亂碼。


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI