初學(xué)者寫的,你可以試試

成都創(chuàng)新互聯(lián)專注于哈爾濱網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供哈爾濱營銷型網(wǎng)站建設(shè),哈爾濱網(wǎng)站制作、哈爾濱網(wǎng)頁設(shè)計、哈爾濱網(wǎng)站官網(wǎng)定制、小程序開發(fā)服務(wù),打造哈爾濱網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供哈爾濱網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
form?name="myform"?method="post"?action="mysql.php"
table?border="1"
tr
td?width="605"?height="51"?bgcolor="#CC99FF"?colspan="2"
div?align="center"請輸入用戶名稱
input?name="txt_user"?type="text"?id="txt_user"?size="25"nbsp;
input?type="submit"?name="Submit"?value="查詢"
/div
/td
/tr
tr
td?align='center'用戶名稱/td
td?align='center'年齡/td
/tr
?php
//?mysql_connect(服務(wù)器,用戶名,密碼)
$link?=?mysql_connect("localhost","root","root");
//?mysql_select_db(數(shù)據(jù)庫,$link)
$db_selected?=?mysql_select_db("php_test",$link);
//?編碼格式(貌似很重要)
mysql_query("set?names?'utf8'");
?
?php
$sql?=?mysql_query("select?name_,age_?from?t_user");
$info?=?mysql_fetch_array($sql);
if($_POST[Submit]=="查詢"){
$txt_user?=?$_POST[txt_user];
$sql?=?mysql_query("select?*?from?t_user?where?name_?like?'%".trim($txt_user)."%'");
$info?=?mysql_fetch_array($sql);
}
?
?php
if($info==false){
echo?'trtd?width="605"?height="51"?bgcolor="#CC99FF"?colspan="2"';
echo?"div?align='center'?style='color:#FF0000;font-size:12px;'對不起,您查找的用戶信息不存在!/div";
echo?'/td/tr';
}elseif($info){
echo?'elseif';
}
?
?php
do{
?
tr?align="center"?bgcolor="#FFFFFF"
td?height="20"align="center"??php?echo?$info['NAME_']?/td
td??php?echo?$info['AGE_']?/td
/tr
?php
}while($info?=?mysql_fetch_array($sql));
mysql_free_result($sql);
mysql_close($link);
?
/table
/form
有個成語叫做有頭有尾,你可以看看性別,年齡那邊是不是完整的?php ?,按照標(biāo)準(zhǔn)的寫法,結(jié)束的分號還得寫全了。
最上面的那一堆的 $_POST["name"],都需要用isset來判斷是否存在才能繼續(xù)在下面使用,不然就會有 Notice: Undefined index: 希望你能記住,千萬得長點心
你確定注冊成功?有沒有寫入數(shù)據(jù)庫呢?你通過數(shù)據(jù)庫管理工具看看你的數(shù)據(jù)庫有沒有你更長提交的東西.
如果沒有很明顯就是沒寫到數(shù)據(jù)庫.
如果有的話就可能是你讀去錯誤!
直接在瀏覽器輸入localhost就知道是否配置成功,另外php文件運行需要放在web目錄下運行,默認(rèn)目前是htdocs這個文件夾,然后通過瀏覽器訪問web地址訪問,不可以直接將php直接拉到瀏覽器上運行(html文件才可以),
在你的代碼最上方加上這一句
ini_set('display_errors','on');
讓他報錯就知道問題在哪了
$conn_ID = mysql_connect('localhost','root','password');
mysql_select_db("secretdata",$conn_ID);
//$sql="select*from whoareyou where username = '$username'";
$result = mysql_query("select*from whoareyou where username = '$username'");
$username = $_POST['username'];
$userpass = $_POST['userpass'];
$howlong = $_POST['howlong'];
if(mysql_fetch_array($result))
{
echo "center h3對不起! 此用戶名已經(jīng)被他人使用,請回到前頁重新輸入:/h3/centerbr";
exit;
}
以上是你代碼的原文,下面是改動后的樣子:
$conn_ID = mysql_connect('localhost','root','password');
mysql_select_db("secretdata",$conn_ID);
$username = $_POST['username']; //將這一行移動到需要使用$username之前,要知道,php是有先后執(zhí)行順序的。
//$sql="select*from whoareyou where username = '$username'";
$result = mysql_query("select*from whoareyou where username = '$username'"); // 也就是這里,在這條語句之前沒有對$username進(jìn)行定義,那么它就永遠(yuǎn)是NULL!!!!!
$userpass = $_POST['userpass']; //
$howlong = $_POST['howlong']; //
if(mysql_fetch_array($result))
{
echo "center h3對不起! 此用戶名已經(jīng)被他人使用,請回到前頁重新輸入:/h3/centerbr";
exit;
}
在沒有if、for、while等改變程序執(zhí)行順序的語句出現(xiàn)時,php是按照語句的先后執(zhí)行順序依次執(zhí)行,下面舉個例子:
echo $a; //這里將不顯示任何東西。
$a=1;
echo $a; //這里將顯示數(shù)字1,而不是下方再次定義后的2!!!
$a=2;
echo $a; //這里將顯示最后一次定義的數(shù)字2!!
另外,強烈建議將數(shù)據(jù)庫連接、查詢、修改等等一系列語句進(jìn)行類的封裝,既安全,又省力。
網(wǎng)頁題目:php注冊表單數(shù)據(jù)的顯示 php登錄表單
網(wǎng)址分享:http://chinadenli.net/article40/hppiho.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、電子商務(wù)、外貿(mào)建站、響應(yīng)式網(wǎng)站、網(wǎng)站建設(shè)、用戶體驗
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)