<body bgcolor = "#cccccc" background = "./3.jpg" width = "100%" height = "100%">
<form method = post action = "click.php">
<center>
<font size = 6 face = 楷體><H1>文章發(fā)布系統(tǒng)<H1></font><br></br>
學(xué)號(hào):<input type = text size = 20 name = num></font><br></br>
密碼:<input type = password size = 20 name = passwd></font><br></br>
<input type = submit h name = click value = 登陸 >
<input type = submit name = click value = 注冊(cè) ><br></br>
</center>
<form method = "post" action = upload_file.php enctype = "multipart/form-data">
文章:<input type = "file" name = "file"><br></br>
文體:<select name = kind><option Value=poem selected>詩(shī)歌
<option Value=prose selected>散文
<option Value=drame selected>戲劇
<option Value=novel selected>小說(shuō)<pre></pre>
</select><br></br>
<input type = submit name = submit value = "發(fā)表">
</form>
<form method = post action = "check.php">
學(xué)號(hào):<input type=text name = userID><br>
姓名:<input type=text name = username><br>
郵箱:<input type=text name = useremail><br>
密碼:<input type=password name = password1><br>
確認(rèn):<input type=password name = password2><br>
<p>
<input type = submit value=注冊(cè)>
<input type = reset value=重置>
1,連接數(shù)據(jù)庫(kù):
/*
連接數(shù)據(jù)庫(kù)
*/
$host = "localhost";
$user = "root";
$password = "password";
$dbase_name = "user";
$table_name = "student";
$conn = mysqli_connect($host,$user,$password);
/*
2,用SESSION保存用戶(hù)的學(xué)號(hào),供所有頁(yè)面同享:
/*
用SESSION保存用戶(hù)的學(xué)號(hào)
實(shí)現(xiàn)所有頁(yè)面內(nèi)同享數(shù)據(jù)
*/
$_SESSION['number'] = $num;
3,操作數(shù)據(jù)庫(kù):
$mysqli_command = "select * from ".$table_name;
$result = mysqli_query($conn,$mysqli_command);
4,保存數(shù)據(jù)庫(kù)復(fù)制的文件到本地:
move_uploaded_file($_FILES["file"]["tmp_name"],
"D:/wamp/www/file/".iconv("UTF⑻","gb2312",$_FILES["file"]["name"]));
MySQL:保存用戶(hù)的基本信息與用戶(hù)的文章發(fā)表記錄,并對(duì)數(shù)據(jù)進(jìn)行操作。
編碼產(chǎn)生的亂碼
產(chǎn)生編碼的緣由是源文件編碼、頁(yè)面編碼、數(shù)據(jù)庫(kù)編碼不1致致使編碼,把這3者的編碼統(tǒng)1的就不會(huì)產(chǎn)生編碼。如果將他們都設(shè)成utf8.
1,源文件編碼
設(shè)定編輯器保存文件的默許編碼,比如EditPlus將保存文件的默許編碼設(shè)為utf8:工具->配置自定義工具->文件->UTF⑻。
2, 頁(yè)面編碼
在HTML代碼的head里告知閱讀器編碼為utf8
<meta http-equiv="Content-Type" content="text/html; charset=UTF⑻"/>
3,數(shù)據(jù)庫(kù)編碼
創(chuàng)建數(shù)據(jù)庫(kù)時(shí)指定編碼格式為utf8
mysql>create database mydb character set utf8;
頁(yè)面之間數(shù)據(jù)同享
1,通過(guò)HTML的form表單,將表單數(shù)據(jù)POST給下1個(gè)頁(yè)面,下1個(gè)頁(yè)面通過(guò)$_POST接受上1個(gè)頁(yè)面POST過(guò)來(lái)的數(shù)據(jù)。
POST
<form method = post action = "check.php">
學(xué)號(hào):<input type=text name = userID><br>
姓名:<input type=text name = username><br>
郵箱:<input type=text name = useremail><br>
密碼:<input type=password name = password1><br>
確認(rèn):<input type=password name = password2><br>
$_POST
$num = mysqli_real_escape_string($conn,$_POST['userID']);
$name = mysqli_real_escape_string($conn,$_POST['username']);
$email = mysqli_real_escape_string($conn,$_POST['useremail']);
$passwd = mysqli_real_escape_string($conn,$_POST['password1']);
2,通過(guò)設(shè)置SESSION保存用戶(hù)的基本信息,實(shí)現(xiàn)所有頁(yè)面同享。SESSION用起來(lái)很簡(jiǎn)單,在代碼最前面開(kāi)啟session_start(),然后把想同享的數(shù)據(jù)保存在
3,cookie,這次沒(méi)用到,感興趣的可以查看PHP手冊(cè)。
主頁(yè)面:
登錄頁(yè)面:
注冊(cè)頁(yè)面:
數(shù)據(jù)庫(kù):
頁(yè)面設(shè)計(jì):
自己獨(dú)立完成的第1個(gè)小項(xiàng)目,自己動(dòng)手寫(xiě)下這篇個(gè)人的第1篇博客,剛開(kāi)始1點(diǎn)頭緒都沒(méi)有,項(xiàng)目根本不知道怎樣做,博客不知道怎樣寫(xiě),但著手開(kāi)始做以后開(kāi)始漸漸了解,漸漸計(jì)劃問(wèn)題的整體框架,然后逐漸去解決問(wèn)題。博客寫(xiě)得確切渣,畢竟第1篇博客和第1個(gè)項(xiàng)目,但還是堅(jiān)持寫(xiě)下來(lái)了,希望自己以后能多鍛煉,能多做項(xiàng)目,然后多寫(xiě)博客,不斷提高自己的水平?!仿湫捱h(yuǎn)兮,吾將上下而求索。
上一篇 Cadence 16.5埋阻埋容PCB設(shè)計(jì)
下一篇 互斥與同步