Home >Backend Development >PHP Tutorial >登记验证一直失败

登记验证一直失败

WBOY
WBOYOriginal
2016-06-13 12:13:011134browse

注册验证一直失败

<?php<br />     require_once 'db.php'; <br />     session_start();<br />     <br />     $name =  $_POST["name"] ;<br />     $mail = $_POST["email"] ;<br />	 $pwd=  $_POST["key"] ;<br />	 $pwd2 =  $_POST["rekey"] ;<br />	 $agreement =  $_POST["agreement"] ;<br />     <br />	 <br />	 if($agreement=="T"){<br />	 	if($pwd==$pwd2){<br />	 		$sql="select * from user";<br />		    $result = $db->query($sql);		 <br />		    if($result && $row=$result->fetch_assoc()){<br />		    	if($name==$row["name"]){<br />			 	 	echo '<script>';<br />			        echo "alert('用户已存在');";<br />					echo "window.location='enroll.html'";<br />			        echo "</script>";<br />					exit;<br />			    }elseif($mail==$row["mail"]){<br />			 	 	echo '<script>';<br />			        echo "alert('该邮箱已使用');";<br />					echo "window.location='enroll.html'";<br />			        echo "</script>";<br />					exit;<br />			 	}else{<br />			 		$sql="insert into user(name,represent,pwd,mail,time) value('{$name}',0,'{$pwd}','{$mail}',now())";<br />					$result = $db->query($sql);<br />					if($result && $db->affected_rows>0){<br />						$sql="select * from user where name='{$name}'";<br />						$result = $db->query($sql);<br />						if($result && $row=$result->fetch_assoc()){<br />							$uid=$row['uid'];<br />						}<br />					}			<br />					$result->free_result;<br />		            $db->close;	<br />					<br />					$sql="insert into userphoto(uid,name,type,url,size,time) value('{$uid}','steve','.png','./img/userphoto/steve.png','6.24kb',now())";<br />				    $result = $db->query($sql);<br />		            if($result && $db->affected_rows>0){<br />				     	echo '<script>';<br />				        echo "alert('注册成功');";<br />				        echo "window.location='index.php'";<br />				        echo "</script>";<br />				        exit;<br />				    }else{<br />				        echo '<script>';<br />				        echo "alert('注册失败');";<br />				        echo "window.location='enroll.html'";<br />				        echo "</script>";<br />						exit;<br />				    }<br />			 	}<br />		    }<br />			$result->free_result;<br />            $db->close;		 	<br />	 	}else{<br />	 		echo '<script>';<br />	        echo "alert('密码不一致,请重新输入');";<br />	        echo "window.location='enroll.html'";<br />	        echo "</script>";<br />			exit;<br />	 	}<br />	 }else{<br />	 	echo '<script>';<br />        echo "alert('未同意协议,注册失败');";<br />		echo "window.location='enroll.html'";<br />        echo "</script>";<br />		exit;<br />	 }   <br />     $result->free_result;<br />     $db->close;<br />?>



用户已经存在,这个一直验证失败,每次注册一样的用户名都是成功,应该怎么改?
------解决思路----------------------
$sql="select * from user"; ???
这个 sql 执行的结果你知道吗?
他将返回 user 表中的全部记录,而你只取出了第一条记录 $row=$result->fetch_assoc()

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn