求一个PHP简单的插入数据库/读取示例。

没有学过php/html等,代码需要简单易懂(效率什么的不要管)
现有数据库主机:localhost,用户:username,密码:password,端口默认。

数据库:eastses,表格classmate

列:"id", "name", "nickname", "birthday", "home", "blood", "qq", "weibo", "email", "phone", "hobby", "food", "sentence", "gift", "lover", "keenon", "unforgettable", "wanttobecome", "ideal", "other"
现在需要一个页面,能够有
例:id:【文本框】
name:【文本框】等等,
然后有个按钮【提交】,可以用用户和密码连接数据库(用户给予所有权限)(如没有数据库或表自动创建)

然后还需要一个网页能够读取数据,吧数据库所有内容列个表格(黑框框就行。),然后首行的"id", "name", "nickname", "birthday", "home", "blood", "qq", "weibo", "email", "phone", "hobby", "food", "sentence", "gift", "lover", "keenon", "unforgettable", "wanttobecome", "ideal", "other"
换成:"ID","姓名""昵称""生日""家庭地址""血型""QQ""微博""weibo""邮箱""手机""爱好""喜欢的食物""最喜欢说的句子""最想收到的礼物""喜欢的食物""最喜欢的Ta""最擅长的事情""难忘的回忆""其他(如已上某某高中等)"
如果懒得换的话列个格式12345下来就行= =
只要能显示就行了。。。。
如果要求太高的话做个插入的页面就行了。。

(ps,做好的文件传附件/网盘,免得格式问题。。)
(pps,虽然匿名,半夜活人,急用,谢谢)

我来给你解决:
只需要一个页面,简单高效,鉴于你的服务器配置各方面都是本地,那么省去很多错误处理:代码见下(复制过去就可以用,字符集一定要正确啊,数据库,meta,names必须要统一):
<!doctype html>
<html>
<head>
<meta charset="utf-8"> <!-- 如果你是GBK或gb2312,请修改utf8为你需要的字符集 -->
<title>列表</title>
</head>

<body>
<?php
//连接数据库
$connect=mysql_connect('localhost','username','password'); //设置字库
mysql_query("SET NAMES utf8"); //如果你是GBK或gb2312,请修改utf8为你需要的字符集,同样上面也要改
mysql_select_db('eastses',$connect); //选择数据库
$table='classmate' //选择数据表
//处理
$do=$_GET['do'];
if($do=="" or $do=="view"){ //打开网页时默认调用本节内容,或者点击浏览时调用本节内容
?>
<!-- html代码开始 -->
<table border="1" cellpadding="0" cellspacing="0">
<thead>
<tr>
<td>ID</td>
<td>姓名</td>
<td>昵称</td>
<td>生日</td>
<td>家庭地址</td>
<td>血型</td>
<td>QQ</td>
<td>微博</td>
<td>邮箱</td>
<td>手机</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代码结束 -->
<?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>
</table><br>
<a href="?do=add">添加信息</a>
<!-- html代码结束 -->
<?php
}elseif($do=="add"){ //点击添加链接时调用本节内容
?>
<!-- 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>
QQ<input type="number" name="qq"><br>
微博<input type="text" name="weibo"><br>
邮箱<input type="email" name="email"><br>
手机<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>
最喜欢的Ta<input 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代码结束 -->
<?php
}elseif($do=="submit"){ //点击提交按钮后调用本节内容
$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\">再添加一组信息</a><br><a href=\"?do=view\">查看信息</a><br>";
}
?>
</body>
</html>
我顶你的肺啊。。CSS和排版格式你可以自己写
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-06-10
http://www.w3school.com.cn/php/php_mysql_connect.asp

PHP连接mySQL数据库 可以查看连接
插入数据看Insert 读取看SELECT 有条件读取看WHERE
第2个回答  2014-06-10
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<?php

if(isset($_POST['tj']))//若点击了提交
{

$conn=mysql_connect("localhost","username","password");
mysql_select_db("eastses",$conn);
mysql_query("set names utf8",$conn);
date_default_timezone_set("asia/chongqing");
$sql = "INSERT INTO `eastses`.`classmate` (`id`, `name`, `nickname`, `birthday`, `home`, `blood`, `qq`, `weibo`, `email`, `phone`, `hobby`, `food`, `sentence`, `gift`, `lover`, `keenon`, `unforgettable`, `wanttobecome`, `ideal`, `other`) VALUES ('".$_POST['id']."', '".$_POST['name']."', '".$_POST['nickname']."', '".$_POST['birthday']."', '".$_POST['home']."', '".$_POST['blood']."', '".$_POST['qq']."', '".$_POST['weibo']."', '".$_POST['email']."', '".$_POST['phone']."', '".$_POST['hobby']."', '".$_POST['food']."', '".$_POST['sentence']."', '".$_POST['gift']."', '".$_POST['lover']."', '".$_POST['keenon']."', '".$_POST['unforgettable']."', '".$_POST['wanttobecome']."', '".$_POST['ideal']."', '".$_POST['other']."');";

if( mysql_query($sql,$conn)>0)
{
echo "<script>alert('数据添加成功!');</script>";}
$res=mysql_query("select * from classmate",$conn);
$i=0;
while($arr=mysql_fetch_array($res))
{
$i++;
echo "第".$i."条数据:";
print_r($arr);
echo "<br><br>";

}
}
?>
<form action="" method="post" name="form1" >
<table width="300" border="0">
<tr>
<td>id:</td>
<td><input type="text" name="id" id="id" /></td>
</tr>
<tr>
<td>name:</td>
<td><input type="text" name="name" id="name" /></td>
</tr>
<tr>
<td>nickname:</td>
<td><input type="text" name="nickname" id="nickname" /></td>
</tr>
<tr>
<td>birthday</td>
<td><input type="text" name="birthday" id="birthday" /></td>
</tr>
<tr>
<td>home</td>
<td><input type="text" name="home" id="home" /></td>
</tr>
<tr>
<td>blood</td>
<td><input type="text" name="blood" id="blood" /></td>
</tr>
<tr>
<td>qq</td>
<td><input type="text" name="qq" id="qq" /></td>
</tr>
<tr>
<td>weibo</td>
<td><input type="text" name="weibo" id="weibo" /></td>
</tr>
<tr>
<td>email</td>
<td><input type="text" name="email" id="email" /></td>
</tr>
<tr>
<td>phone</td>
<td><input type="text" name="phone" id="phone" /></td>
</tr>
<tr>
<td>hobby</td>
<td><input type="text" name="hobby" id="hobby" /></td>
</tr>
<tr>
<td>food</td>
<td><input type="text" name="food" id="food" /></td>
</tr>
<tr>
<td>sentence</td>
<td><input type="text" name="sentence" id="sentence" /></td>
</tr>
<tr>
<td>gift</td>
<td><input type="text" name="gift" id="gift" /></td>
</tr>
<tr>
<td>lover</td>
<td><input type="text" name="lover" id="lover" /></td>
</tr>
<tr>
<td>keenon</td>
<td><input type="text" name="keenon" id="keenon" /></td>
</tr>
<tr>
<td>unforgettable</td>
<td><input type="text" name="unforgettable" id="unforgettable" /></td>
</tr>
<tr>
<td>wanttobecome</td>
<td><input type="text" name="wanttobecome" id="wanttobecome" /></td>
</tr>
<tr>
<td>ideal</td>
<td><input type="text" name="ideal" id="ideal" /></td>
</tr>
<tr>
<td>other</td>
<td><input type="text" name="other" id="other" /></td>
</tr>

<tr>
<td><input type="submit" name="tj" id="tj" value="提交" /></td>
<td></td>
</tr>
</table>
</form>
</body>
</html>本回答被提问者采纳
相似回答