設計界面:php
開學到如今了:作用戶註冊,功能加了再加...仍是有待提升...mysql
下面是個人學習成果,PHP代碼:sql
<body>數據庫
<?phpide
mysql_connect('localhost','root','123456');post
//鏈接數據庫('地址','用戶','密碼');學習
mysql_select_db('yy'); //選擇數據庫spa
mysql_set_charset('utf8'); //修改字符集設計
if(isset($_POST['aaa'])){ //判斷值爲aaa的按鈕是否按了orm
$username=$_POST['username'];
//把文本的name屬性爲username的值賦予給變量$username
$password=$_POST['password']; //同上
$password2=$_POST['password2'];
$sex=$_POST['radio'];
$cs =$_POST['cs']."-".$_POST['b']."-".$_POST['c'];
//這個是作到日期選擇的時候就會用到的了:若是有三個變量的值,你須要存入到數據庫的一個字段中的時候,就須要用到.「」 .了! ."-"中間的能夠設置格式之類的
$wh=$_POST['wh'];
$array_class=$_POST['class'];
$class=implode(',',$array_class);
$email=$_POST['email'];
if($password!=$password2){
exit('你兩次輸入的密碼不一致,請<a href="regedit.php">返回</a>從新輸入!');
}
//這是判斷兩次密碼的輸入是否正確的。if 變量$password的值不等於變量$password2的值的話,就exit轉跳到一個新網頁,並輸出''中的內容:
$sql="insert into users(username,password,sex,cs,wh,ah,email) values('{$username}','{$password}','{$sex}','{$cs}','{$wh}','{$class}','{$email}')";
//把sql語句的值存入到變量$sql中;
$result=mysql_query($sql);//數據庫查詢的結果存入到變量$result中
if($result && mysql_affected_rows){
//若是變量$result的值在數據庫中的行有變化
echo "<script>alert('註冊成功');</script>";//彈出註冊成功的窗口
}else{
echo "<script>alert('註冊失敗');</script>";
}
}
?>
<?php
if(isset($_POST['fff'])){
$username = $_REQUEST['username'];
mysql_connect('localhost','root','123456');
mysql_select_db('yy');
$sql="select * from users where username=$username";
$query=mysql_query($sql);
if(mysql_num_rows($query)>0){
//若是變量$query在數據庫中的行變化大於0的話,就出輸出
echo "<script>alert('用戶名已存在');</script>";
}else{
echo "<script>alert('用戶名能夠使用');</script>";}}
?>
<h1>用戶註冊</h1>
<form method="post"><table>
<tr>
<td>帳號:</td>
<td><input name="username" type="text" id="username" />
<input type="submit" name="fff" value="檢測用戶名" /></td>
</tr>
<tr>
<td>密碼:</td>
<td><input name="password" type="password" id="password" /></td>
</tr>
<tr>
<td>從新輸入密碼:</td>
<td><input name="password2" type="password" id="password2" /></td>
</tr>
<tr>
<td>性別:</td>
<td><input name="radio" type="radio" value="男" checked/>男
<input type="radio" value="女" name="radio"/>女</td>
</tr>
<tr>
<td>出生日期:</td>
<td><select name="cs" id="a">
<?php
for ($a =1992; $a <2020;$a++) {
echo "<option>$a</option> "; }?>
</select>
//這裏我用for循環語句實在選擇項
<select name="b" id="b">
<?php
for ($a =1; $a <13;$a++) {
echo "<option>$a</option> "; }?>
</select>
<select name="c" id="c">
<?php
for ($a =1; $a <32;$a++) {
echo "<option>$a</option> "; }?>
</select>
</td>
</tr>
<tr>
<td>文化程程:</td>
<td>
<input type="radio" name="wh" value="小學 "/>小學
<input type="radio" name="wh" value="初中"/>初中
<input type="radio" name="wh" value="高中" checked />高中
<input type="radio" name="wh" value="大專"/>大專
<input type="radio" name="wh" value="本科"/>本科
<input type="radio" name="wh" value="碩士"/>碩士
<input type="radio" name="wh" value="博士"/>博士
</td>
</tr>
<tr>
<td>體育愛好:</td>
<td>
<input type="checkbox" value="籃球" name="class[]"/>籃球
<input name="class[]" type="checkbox" value="足球" />足球
<input type="checkbox" value="乒乓球" name="class[]" />乒乓球
<input name="class[]" type="checkbox" value="羽毛球" />羽毛球
<input name="class[]" type="checkbox" value="其它" />其它
</td>
</tr>
<tr>
<td>E-mail:</td>
<td><input name="email" type="text" id="email" /><br />
<input type="submit" name="aaa" value="註冊" />
<input type="submit" value="返回" />
<input type="reset" value="重置" /></td>
</tr>
</table>
</form>
</body>