insert_form.html(表單頁面):
創(chuàng)新互聯(lián)建站主營裕安網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,重慶APP軟件開發(fā),裕安h5成都小程序開發(fā)搭建,裕安網(wǎng)站營銷推廣歡迎裕安等地區(qū)企業(yè)咨詢
form action="insert.php" method="post"
用戶名: input type="text" name="username" /
br /
電子郵箱: input type="text" name="email" /
br /
input type="submit" /
/form
insert.php(寫入數(shù)據(jù)頁面):
?php
$conn = @mysql_connect("localhost","root","root123");
if (!$conn){
die("連接數(shù)據(jù)庫失敗:" . mysql_error());
}
mysql_select_db("test", $conn);
mysql_query("set names 'gbk'"); //為避免中文亂碼做入庫編碼轉(zhuǎn)換
if($_POST){
$sql = "INSERT INTO user (username email) VALUES ('$_POST[username]', '$_POST[email]')";
if(!mysql_query($sql,$conn)){
echo "添加數(shù)據(jù)失?。?.mysql_error();
} else {
echo "添加數(shù)據(jù)成功!";
}
}
請將mysql_connect("localhost","root","root123");中的用戶名和密碼更改是實際的。
?
查詢表單.HTML
form action=search.php method=get
keyword:input name=key value="" type=textinput type=submit value="submit"
/form
search.php
?php
$dbhost="數(shù)據(jù)庫地址";
$dbuser="數(shù)據(jù)庫用戶名";
$dbpwd="數(shù)據(jù)庫密碼";
$database="數(shù)據(jù)庫名";
$key=$_GET['key'];
$db_source = mysql_connect($dbhost, $dbuser, $dbpwd);
mysql_select_db($database, $db_source) or die("數(shù)據(jù)庫連接出錯!");
mysql_query("set names GBK");
?
style
*{font-size:14px;}
body{padding:0;margin:0}
th,td{padding:10px}
/style
h1搜索結(jié)果/h1
?php
$pagesize=3;
//取得記錄總數(shù)$rs,計算總頁數(shù)用
$rs=mysql_query("select count(id) from tb_news where title like '%".$key."%'",$db_source);
$myrow = mysql_fetch_array($rs);
$numrows=$myrow[0];
//計算總頁數(shù)
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize)
{$pages++;}
//設(shè)置頁數(shù)
if (isset($_GET['page'])){
$page=intval($_GET['page']);
}
else{
//設(shè)置為第一頁
$page=1;
}
//計算記錄偏移量
$offset=$pagesize*($page - 1);
//讀取指定記錄數(shù)
$rs=mysql_query("select * from tb_news where title like '%".$key."%' order by id desc limit $offset,$pagesize",$db_source);
if ($myrow = mysql_fetch_array($rs))
{
$i=0;
do {
?
這里為循環(huán)代碼,單獨(dú)出來了
?php echo "a href=Show.php?id=".$myrow["id"]."".$myrow["title"]."/a";?br
?php
$i++;
}
while ($myrow = mysql_fetch_array($rs));
}
echo "div align='center'共有".$pages."頁(".$page."/".$pages.")";
for ($i=1;$i$page;$i++)
echo "a href='?page=".$i."key=".$key."'[".$i ."]/a ";
echo "[".$page."]";
for ($i=$page+1;$i=$pages;$i++)
echo "a href='?page=".$i."key=".$key."'[".$i ."]/a ";
echo "/div";
?
我來給你解決:
只需要一個頁面,簡單高效,鑒于你的服務(wù)器配置各方面都是本地,那么省去很多錯誤處理:代碼見下(復(fù)制過去就可以用,字符集一定要正確啊,數(shù)據(jù)庫,meta,names必須要統(tǒng)一):
!doctype html
html
head
meta charset="utf-8" !-- 如果你是GBK或gb2312,請修改utf8為你需要的字符集 --
title列表/title
/head
body
?php
//連接數(shù)據(jù)庫
$connect=mysql_connect('localhost','username','password'); //設(shè)置字庫
mysql_query("SET NAMES utf8"); //如果你是GBK或gb2312,請修改utf8為你需要的字符集,同樣上面也要改
mysql_select_db('eastses',$connect); //選擇數(shù)據(jù)庫
$table='classmate' //選擇數(shù)據(jù)表
//處理
$do=$_GET['do'];
if($do=="" or $do=="view"){ //打開網(wǎng)頁時默認(rèn)調(diào)用本節(jié)內(nèi)容,或者點(diǎn)擊瀏覽時調(diào)用本節(jié)內(nèi)容
?
!-- html代碼開始 --
table border="1" cellpadding="0" cellspacing="0"
thead
tr
tdID/td
td姓名/td
td昵稱/td
td生日/td
td家庭地址/td
td血型/td
tdQQ/td
td微博/td
td郵箱/td
td手機(jī)/td
td愛好/td
td喜歡的食物/td
td最喜歡說的句子/td
td最想收到的禮物/td
td最喜歡的Ta/td
td最擅長的事情/td
td難忘的回憶/td
td偶像/td
td理想/td
td其他/td
/tr
/thead
tbody
!-- html代碼結(jié)束 --
?php
$result=mysql_query("SELECT * FROM $table"); //查詢表中所有記錄
while($row=mysql_fetch_array($result)){
echo
"tr",
"td".$row['0']."/td",
"td".$row['1']."/td",
"td".$row['2']."/td",
"td".$row['3']."/td",
"td".$row['4']."/td",
"td".$row['5']."/td",
"td".$row['6']."/td",
"td".$row['7']."/td",
"td".$row['8']."/td",
"td".$row['9']."/td",
"td".$row['10']."/td",
"td".$row['11']."/td",
"td".$row['12']."/td",
"td".$row['13']."/td",
"td".$row['14']."/td",
"td".$row['15']."/td",
"td".$row['16']."/td",
"td".$row['17']."/td",
"td".$row['18']."/td",
"td".$row['19']."/td",
"/tr";
}
?
!-- html代碼開始 --
/tbody
/tablebr
a href="?do=add"添加信息/a
!-- html代碼結(jié)束 --
?php
}elseif($do=="add"){ //點(diǎn)擊添加鏈接時調(diào)用本節(jié)內(nèi)容
?
!-- html代碼開始 --
form action="?do=submit" method="get"
姓名input type="text" name="name"br
昵稱input type="text" name="nickname"br
生日input type="text" name="birthday"br
家庭地址input type="text" name="home"br
血型input type="text" name="blood"br
QQinput type="number" name="qq"br
微博input type="text" name="weibo"br
郵箱input type="email" name="email"br
手機(jī)input type="number" name="phone"br
愛好input type="text" name="hobby"br
喜歡的食物input type="text" name="food"br
最喜歡說的句子input type="text" name="sentence"br
最想收到的禮物input type="text" name="gift"br
最喜歡的Tainput type="text" name="lover"br
最擅長的事情input type="text" name="keenon"br
難忘的回憶input type="text" name="unforgettable"br
偶像input type="text" name="wanttobecome"br
理想input type="text" name="ideal"br
其他input type="text" name="other"br
button type="submit" name="submit"提交/button
button type="reset" name="reset"重新填寫/button
/form
!-- html代碼結(jié)束 --
?php
}elseif($do=="submit"){ //點(diǎn)擊提交按鈕后調(diào)用本節(jié)內(nèi)容
$name=$_GET['name'];
$nickname=$_GET['nickname'];
$birthday=$_GET['birthday'];
$home=$_GET['home'];
$blood=$_GET['blood'];
$qq=$_GET['qq'];
$weibo=$_GET['weibo'];
$email=$_GET['email'];
$phone=$_GET['phone'];
$hobby=$_GET['hobby'];
$food=$_GET['food'];
$sentence=$_GET['sentence'];
$gift=$_GET['gift'];
$lover=$_GET['lover'];
$keenon=$_GET['keenon'];
$unforgettable=$_GET['unforgettable'];
$wanttobecome=$_GET['wanttobecome'];
$ideal=$_GET['ideal'];
$other=$_GET['other'];
$result=mysql_query("INSERT INTO $table(id,name,nickname,birthday,home,blood,qq,weibo,email,phone,hobby,food,sentence,gift,lover,keenon,unforgettable,wanttobecome,ideal,other) VALUES(NULL,$name,$nickname,$birthday,$home,$blood,$qq,$weibo,$email,$phone,$hobby,$food,$sentence,$gift,$lover,$keenon,$unforgettable,$wanttobecome,$ideal,$other)"); //按字插入
echo"a href=\"?do=add\"再添加一組信息/abra href=\"?do=view\"查看信息/abr";
}
?
/body
/html
我頂你的肺啊。。CSS和排版格式你可以自己寫