PHP中获取MySQL信息,并写入表单中??

来源:百度知道 编辑:UC知道 时间:2024/05/27 07:40:09
我想把从MySQL中查出的值放入 PHP表单中、、
代码如下。可不对。。应该怎么写??
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
<html>
<body>

<?php
$name=$_POST[names];
$link=mysql_connect("localhost","root","123");

$db=mysql_select_db("library");

mysql_query("set names gb2312");

$sql="select * from user where ID='$name'";

$result = mysql_query($sql,$link);

while($ss=mysql_fetch_array($result)){

echo "$ss[1] $ss[2] $ss[3] $ss[4]";

}

?>
<form name="gry" method="post">
账号 :<input type="text" name="a" value="<?php $ss[1]; ?>"><br>
密码 :<input type="password" name="b" value="<?php $ss[2]; ?>"><br><

由于你取的记录只有一行,因此不要放到循环中:
while($ss=mysql_fetch_array($result)){

echo "$ss[1] $ss[2] $ss[3] $ss[4]";

}

以上可改为:

$row = mysql_fetch_assoc($result); //$row是一个关联数组,每个键就是数据库的各个字段。

另外你这里面有一点问题:
<input type="text" name="a" value="<?php $ss[1]; ?>">

并没有把它打印出来。改为以下即可:
<input type="text" name="a" value="<?php echo $ss[1]; ?>">

主要是少了个 = 号 或者你用echo 也可以啦

value="<?php =$ss[3]; ?>" 或者 value="<?php echo $ss[3]; ?>"这个是关键所在。