php登入註冊

來源:互聯網
上載者:User

標籤:重試   asc   登入   hone   etc   password   sql   als   money   

在度娘協助下終於完成php登入註冊,在這個過程中學習到了一些php 中的MySQL()函數。

登入頁面html:

<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>登入</title>
<style>
html{font-size:12px;}
fieldset{width:300px; margin: 0 auto;}
legend{font-weight:bold; font-size:14px;}
label{float:left; width:70px; margin-left:10px;}
.left{margin-left:80px;}
.input{width:150px;}
span{color: #666666;}
</style>
</head>
<body>
<div>
<fieldset>
<legend>使用者登入</legend>
<form name="LoginForm" method="post" action="login.php" onSubmit="return InputCheck(this)">
<p>
<label for="username" class="label">姓名:</label>
<input id="username" name="username" type="text" class="input" />
</p>
<p>
<label for="password" class="label">密 碼:</label>
<input id="password" name="password" type="password" class="input" />
</p>
<p>
<input type="submit" name="submit" value=" 確 定 " class="left" />
</p>
<p>
<a href = "register.html">立即註冊</a>
</p>
</form>
</fieldset>
</div>
<script language=JavaScript>
function InputCheck(LoginForm)
{
if (LoginForm.username.value == "")
{
alert("請輸入使用者名稱!");
LoginForm.username.focus();
return (false);
}
if (LoginForm.password.value == "")
{
alert("請輸入密碼!");
LoginForm.password.focus();
return (false);
}
}
</script>
</body>
</html>

 

登入頁面php:

<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>登入</title>
</head>
<body>

<?php
//包含資料庫連接檔案
include(‘conn.php‘);
session_start();

//登入
if(!isset($_POST[‘submit‘])){
exit(‘非法訪問!‘);
}
$username = htmlspecialchars($_POST[‘username‘]);
$password = $_POST[‘password‘];

//包含資料庫連接檔案
include(‘conn.php‘);
//檢測使用者名稱及密碼是否正確;
$check_query = mysql_query("select username,password from user where username=‘$username‘ limit 1");
$num = mysql_num_rows($check_query);
if($num){
$row = mysql_fetch_array($check_query);
if($username==$row[0] && $password==$row[1]){
echo $username,‘ 歡迎你!進入 <a href="money.php">使用者中心</a><br />‘;
exit;
}else{
exit(‘登入失敗!帳號或密碼錯誤,點擊此處 <a href="javascript:history.back(-1);">返回</a> 重試‘);
}
}
?>
</body>
</html>

 註冊頁面:

<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>註冊</title>
<style>
html{font-size:12px;}
fieldset{width:300px; margin: 0 auto;}
legend{font-weight:bold; font-size:14px;}
label{float:left; width:70px; margin-left:10px;}
.left{margin-left:80px;}
.input{width:150px;}
span{color: #666666;}
</style>
</head>
<body>
<fieldset>
<legend>使用者註冊(必須填寫完整)</legend>
<form name="LoginForm" method="post" action="register.php" onSubmit="return InputCheck(this)">
<p>
<label for="account" class="label">姓名:</label>
<input id="account" name="username" type="text" class="input" />
</p>
<p>
<label for="number" class="label">手機號:</label>
<input id="number" name="phone" type="text" class="input" />
</p>
<p>
<label for="password" class="label">密碼:</label>
<input id="password" name="password" type="password" class="input" />
<p style="margin-left: 100px;">密碼長度6-18位</p>
</p>
<p>
<label for="repassword" class="label">確認密碼:</label>
<input id="repassword" name="repassword" type="password" class="input" />
</p>
<p>
<input type="submit" name="submit" value=" 確 定 " class="left" />
</p>
</form>
</fieldset>


</body>
</html>

註冊頁面php:

<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>註冊</title>
</head>
<body>
<?php
//包含資料庫連接檔案
include(‘conn.php‘);
if(!isset($_POST[‘submit‘])){
exit(‘非法訪問!‘);
}
$username = $_POST[‘username‘];
$password = $_POST[‘password‘];
$repassword = $_POST[‘repassword‘];
$phone = $_POST[‘phone‘];

//註冊資訊判斷
if(strlen($password) < 6){
exit(‘錯誤:密碼長度不符合規定。<a href="javascript:history.back(-1);">返回</a>‘);
}
if($username == "" || $password == "" || $repassword == "" || $phone ==""){
echo "<script>alert(‘請確認資訊完整性!‘); history.go(-1);</script>";
}else{
if($password == $repassword){
//檢測使用者名稱是否已經存在
$check_query = mysql_query("select id from user where username=‘$username‘ limit 1");
if(mysql_fetch_array($check_query)){
//echo "mysql_fetch_array($check_query)";
echo ‘錯誤:姓名 ‘,$username,‘ 已存在。<a href="javascript:history.back(-1);">返回</a>/<a href="login.html">登入</a>‘;
exit;
}
//寫入資料
$password = $password;
$regdate = time();
$sql = "INSERT INTO user(username,phone,password)VALUES(‘$username‘,‘$phone‘,‘$password‘)";
if(mysql_query($sql,$conn)){
exit(‘使用者註冊成功!點擊此處 <a href="login.html">登入</a>‘);
} else {
echo ‘抱歉!添加資料失敗:‘,mysql_error(),‘<br />‘;
echo ‘點擊此處 <a href="javascript:history.back(-1);">返回</a> 重試‘;
}
}else{
echo "<script>alert(‘密碼不一致!‘); history.go(-1);</script>";
}

}


?>
</body>
</html>

 

money.php

<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>賬單</title>
<style>
table{width:500px;marigin: 0 auto}
table tr{height: 30px;}
table tr td{text-align: center;}
table tr:nth-child(2n+1){background: #F4F4F4; }
</style>
</head>
<body>
<?php
//包含資料庫連接檔案
include(‘conn.php‘);
?>
<p class="">總賬:
<?php
$p = "select*from total";
$money = mysql_query($p);
$q = "select*from Bill";//設定查詢指令
$result = mysql_query($q);//執行查詢
while($s = mysql_fetch_assoc($money)){
while($row = mysql_fetch_assoc($result)){
$s["qian"] = $s["qian"] + $row["in_outcome"];
}
echo "<span>".$s["qian"]."</span>";
}
?>
</p>
<table>
<tr>
<td>編號</td>
<td>進出賬目</td>
<td>來源/接收</td>
</tr>
<?php
$q = "select*from Bill";//設定查詢指令
$result = mysql_query($q);//執行查詢
while($row = mysql_fetch_assoc($result))//將result結果集中查詢結果
{
//echo "$row[in_outcome]";
echo"<tr><td>".$row["id"]."</td><td>".$row["in_outcome"]."</td><td>".$row["username"]."</td></tr>";
};

?>

</table>
</body>
</html>

php登入註冊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.