求mySQL的一个简单语句

geoella 2009-01-08 01:55:39

问一个简单问题,就是用户登录以后到一个表单页面,表单里面的各个文本域显示用户在数据里记录的信息,用户可以重新修改这些信息并保存,这个怎么做? 谢谢啊!
$query = "SELECT Business_Owner,Business_Name, Mailing_Address,Phone_Number,Crop_Type,Crop_Location,Section,Township,Range,Quarter,Acreage FROM pesticide_sensitive_crop where userid = ".$_GET["userid"].";";

主要问题就是怎么把上面从数据库提取的这些 Business_Owner,Business_Name,Mailing_Address等等分别赋值给表单里的各个文本域?? 谢谢大家!!


...全文
166 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
cyxin2121921 2009-01-09
  • 打赏
  • 举报
回复
mark
baige1210 2009-01-09
  • 打赏
  • 举报
回复
同意楼上!
meirenxing 2009-01-09
  • 打赏
  • 举报
回复
...这两天smarty写多了 所以写了value=" <{$info['Business_Owner']}>"。 不好意思 ,这样是显示不出来。

9楼的方法是对的,用 value="<?php echo $row[Name] ?>" 是能显示出来的

还有$array=array($result); 不能这样的到查询出来的数组,用mysql_fetch_array 或者是 mysql_fetch_assoc 可以看看手册
frederic_zhao 2009-01-09
  • 打赏
  • 举报
回复

<?php
mysql_connect("localhost", "user", "pwd") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

$query = "SELECT Name,Mailing_Address,City,State,Zip,Phone_Number,Cell_Number FROM pesticide_sensitive_crop WHERE Email= =connie@faltys.com ";
$result = mysql_query($query);

$row = mysql_fetch_array($result);

?>
<input type="text" name="x" value="<?php echo $row[Name] ?>" />
<input type="text" name="y" value="<?php echo $row[Mailing_Address] ?>" />
<input type="text" name="z" value="<?php echo $row[City] ?>" />

这样就行!
geoella 2009-01-09
  • 打赏
  • 举报
回复
此外,用数组做了,我的代码出错了,所以调不出来数据,大家帮我看看吧,谢谢了
<?php
$query = "SELECT Name,Mailing_Address,City,State,Zip,Phone_Number,Cell_Number FROM pesticide_sensitive_crop WHERE Email= =connie@faltys.com ";
$result = mysql_query($query);
$array=array($result);

?〉
<input type="text" id="Name" name="Name" value="$array['0']"; >
<input type="text" id="Mailing_Address" name="Mailing_Address" value="$array['1']">

是不是$result = mysql_query($query);
$array=array($result); 这个地方错了?怎么把数据库取出来的值直接赋值给数组呢?


帮帮忙阿,菜鸟啊

geoella 2009-01-09
  • 打赏
  • 举报
回复
<?php
$query = "SELECT Business_Owner,Business_Name, Mailing_Address,Phone_Number,Crop_Type,Crop_Location,Section,Township,Range,Quarter,Acreage FROM pesticide_sensitive_crop where userid = ".$_GET["userid"].";";

$result = mysql_query($query);
if($row = mysql_fetch_assoc($result)){
$info = $row;
}
?>
...
<input type="text" id="Business_Owner" name="Business_Owner" value=" <{$info['Business_Owner']}>">
<input type="text" id="Business_Name" name="Business_Name" value=" <{$info['Business_Name']}>">
<input type="text" id="Mailing_Address" name="Mailing_Address" value=" <{$info['Mailing_Address']}>">
...


试过了,文本域显示不出从数据库提出来的数据??
xuexihappy_Dtw 2009-01-08
  • 打赏
  • 举报
回复
同上
meirenxing 2009-01-08
  • 打赏
  • 举报
回复
<?php
$query = "SELECT Business_Owner,Business_Name, Mailing_Address,Phone_Number,Crop_Type,Crop_Location,Section,Township,Range,Quarter,Acreage FROM pesticide_sensitive_crop where userid = ".$_GET["userid"].";";

$result = mysql_query($query);
if($row = mysql_fetch_assoc($result)){
$info = $row;
}
?>
...
<input type="text" id="Business_Owner" name="Business_Owner" value="<{$info['Business_Owner']}>">
<input type="text" id="Business_Name" name="Business_Name" value="<{$info['Business_Name']}>">
<input type="text" id="Mailing_Address" name="Mailing_Address" value="<{$info['Mailing_Address']}>">
...

文本框默认显示出查询出来的结果。提交表单后,获取文本框内容,修改数据库记录。

我是菜鸟,一起学习
sword_88 2009-01-08
  • 打赏
  • 举报
回复
学习一下!
宇晨007 2009-01-08
  • 打赏
  • 举报
回复
数据库取出的放到数组
$array
<input type=text value="array['Business_Owner']" name=Business_Owner>

这样
xk_520 2009-01-08
  • 打赏
  • 举报
回复
<tr align="conter">
<a>标 题:</a> 
<input type="text" name="title" value="<{$Htitle}>" size="60">
</tr>
在用POST 或 GET 获取就可以了
free999 2009-01-08
  • 打赏
  • 举报
回复
结果拿到了吗?
就是说关于用户信息的数组

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧