21,886
社区成员
发帖
与我相关
我的任务
分享
$password;
$username; //假设你已经得到这两个变量了
<html>
<body>
<table>
<tr><?php echo $username; ?><//tr>
<tr><?php echo $password; ?><//tr>
</table>
</body>
</html>
// 创建数据库
CREATE TABLE `user` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(20) NOT NULL, `password` varchar(100) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1;
插入表数据
INSERT INTO `test`.`user` (`id` ,`name` ,`password`)VALUES (NULL , 'fdipzone', '123');
INSERT INTO `test`.`user` (`id` ,`name` ,`password`)VALUES (NULL , 'csdn', '456');
php代码
<?php
//打开数据库
function opendb(){
$conn=@mysql_connect("localhost","root","") or die(mysql_error());
@mysql_select_db('test',$conn) or die(mysql_error());
}
opendb();
echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">';
$sqlstr = "select * from user";
$query = mysql_query($sqlstr) or die(mysql_error());
while($thread=mysql_fetch_assoc($query)){
$result[] = $thread;
}
if($result){
echo '<table><tr><td>name</td><td>password</td></tr>';
foreach($result as $val){
echo '<tr><td>'.$val['name'].'</td><td>'.$val['password'].'</td></tr>';
}
echo '</table>';
}
?>
<?php foreach($pdo->query($sql) as $rows){?>
<table>
<tr>
<td><input type="text" name="name" value="<?=$rows['name'] ?>" /></td>
</tr>
</table>
<?php
}
?>