想寫就會盡快去寫。如果用php寫了就一定要用nodejs寫出來啊,不寫是小狗啊!
補充一下,想要實現的功能:
1.用戶名重復檢測
2.檢測信息填寫是否完整
3.郵箱是否已經被注冊
4.實現ajax無刷新
5.注冊成功后跳轉到一個index導航頁面,並且右上角顯示用戶名
6.index導航頁面中有導航欄,分別是:首頁(顯示文章) 發布文章頁面(文章實現可編輯)、可評論,可分享、可贊...
7.密碼長度檢測並提示
html文件叫1.html,文件代碼:
<!DOCTYPE html> <html> <head> <title>adc</title> <meta charset="utf-8"> </head> <body> <form action="zhuce.php" method="post"> <p><input id="user" name="user" type="text" placeholder="用戶名"/></p> <p><input id="psd1" name="psd1" type="password" placeholder="密碼"/></p> <p><input id="psd2" name="psd2" type="password" placeholder="驗證密碼"/></p> <p><input id="eml" name="eml" type="email" placeholder="郵箱"/></p> <p><input id="sbt" name="sbt" type="submit" placeholder="提交"/></p> </form> </body> </html>
php文件名為zhuce.php,代碼:
<?php header("content-type:text/html;charset=utf-8");//這個貌似是設置字符編碼吧,不然的話頁面輸出回事亂碼 //開啟session,b不明白?沒關系,我待會再在下面單獨說 session_start(); //接收表單傳遞的用戶名和密碼 $name=$_POST['user'];//$_POST[],這個大神們都應該知道,就是獲取前端表單傳回來的數據,並且是通過input的name屬性值來獲取,看到沒?我index.html中有一個input的name值是user的 $pwd=$_POST['psd1'];//以下同上 $repwd=$_POST['psd2']; $email=$_POST['eml']; //下面判斷信息是不是輸入完整 if(empty($name)||empty($pwd)||empty($repwd)||empty($email)){ echo "<script>alert('你逗我?信息輸入沒完整');</script>"; echo "<script>window.location='index.html';</script>"; }else //判斷密碼是否一 致 if ($pwd!=$repwd) { echo"<script>alert('兩次密碼輸入不一致,請重新輸入');</script>"; echo"<script>location='index.html'</script>"; }else{ //通過php連接到mysql數據庫 $conn=mysqli_connect("localhost","root","",'zhuce'); //選擇數據庫 $sql1 = "SELECT * FROM t1 WHERE username='$name'"; $result = mysqli_query($conn,$sql1); $rows = mysqli_num_rows($result); if($rows>0) { echo "<script>alert('用戶名已經有人注冊了,重新注冊一個吧')</script>"; echo "<script>window.location='index.html'</script>"; } else { echo "用戶名可用\n"; //設置客戶端和連接字符集 mysqli_query($conn,"set names utf8"); //通過php進行insert操作 $sqlinsert="insert into t1(username,password,email) values('{$name}','{$pwd}','{$email}')"; //返回用戶信息字符集 $result=mysqli_query($conn,$sqlinsert); if(! $result ) { die('Could not enter data: ' . mysql_error()); } echo "恭喜你注冊成功\n"; //釋放連接資源 mysqli_close($conn); } } ?>
數據庫名為zhuce,表名為t1,以后詳細講。