//注冊(cè)頁面<!DOCTYPE html><html><head>?<title>注冊(cè)頁</title>?<meta charset="utf-8">?<style type="text/css">??*{???margin:0px;padding:0px;??}??.gray{???width:333px;???height:444px;???background-color:lightgray;???margin:88px auto;???border-radius:5px;??}??table??{???margin:0px auto;??}??table caption??{???margin-top:40px;??}?</style>?<script type="text/javascript">??function checkname(oInput)??{???var xmlhttp;???var span=document.getElementById('s');???var name=document.getElementById('name');???if(oInput.value=="")???{????span.innerHTML="請(qǐng)輸入賬號(hào)";????span.style.color='red';????name.focus();????return;???}???if(window.ActiveXObject)???{????xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');???}???else???{????xmlhttp=new XMLHttpRequest();???}???xmlhttp.open('post','checkname.php',true);???xmlhttp.onreadystatechange=function()???{????if(xmlhttp.readyState==4 && xmlhttp.status==200)????{?????var result=xmlhttp.responseText;?????if(result=='yes')?????{??????span.innerHTML='';?????}?????else?????{??????span.innerHTML='賬號(hào)已被注冊(cè)';??????span.style.color='red';?????}????}???}???xmlhttp.setRequestHeader('content-type','application/x-www-form-urlencoded');???xmlhttp.send('name='+oInput.value);??}?</script></head><body>?<div class="gray">??<form action="check.php" method="post">???<table>????<caption align="center">新用戶注冊(cè)</caption>????<tr>?????<td>用戶名</td>????</tr>????<tr>?????<td><input type="text" name="name" onblur="checkname(this)" id="name"><span id="s"></span></td>????</tr>????<tr>?????<td>密碼</td>????</tr>????<tr>?????<td><input type="password" name="pwd"></td>????</tr>????<tr>?????<td>確認(rèn)密碼</td>????</tr>????<tr>?????<td><input type="password" name="repwd"></td>????</tr>????<tr>?????<td>電子郵件</td>????</tr>????<tr>?????<td><input type="text" name="email"></td>????</tr>????<tr>?????<td>個(gè)人主頁</td>????</tr>????<tr>?????<td><input type="text" name="homepage"></td>????</tr>????<tr>?????<td colspan="2" align="center"><input type="submit" value="注冊(cè)" name="btnadd"></td>????</tr>???</table>??</form>?</div></body></html>//想用php把注冊(cè)的信息添加到數(shù)據(jù)庫中<?php?header('content-type:text/html;charset=utf-8;');?$name=$_POST['name'];?$pwd=md5($_POST['pwd']);?$email=$_POST['email'];?$homepage=$_POST['homepage'];?$pdo=new PDO('mysql:host=localhost;dbname=reg','root','',array(PDO::MYSQL_ATTR_INIT_COMMAND=>"set names 'utf8'"));?$sql="select count(userid) from users where name=$name";?$sql2="insert into users values($name,$pwd,$email,$homepage)";?$recordset=$pdo->query($sql);?$recordset->setFetchMode(PDO::FETCH_NUM);?$result=$recordset->fetch();?print_r($result);?if($result[0]>0)?{??echo 'no';?}?else?{??echo 'yes';?}?if($pdo->exec($sql2))?{??echo '注冊(cè)成功';?}?else?{??echo '失敗';?}?$pdo=null;//總是說我姿勢不對(duì),瘋了要,覺得程序員每天不是在寫代碼,是在找錯(cuò)誤排查,啊啊啊啊啊w(?Д?)w//寫了20分鐘,哈哈,搞定,運(yùn)行,錯(cuò)誤,然后我就找了一天的錯(cuò)誤,到底是哪里錯(cuò)了呢?
- 1 回答
- 1 關(guān)注
- 1816 瀏覽
添加回答
舉報(bào)
0/150
提交
取消