PHP获取数据库表中字段的值

haihao_110 2010-08-03 11:14:05
通过第一页的按钮
<a href="up_load.php?hid=' . $row['h_id'] . '">编辑</a>
,在第二页获取选定的值,并把值传递到第二页input中
<table border=1 height=100 width=400 align="center">
<tr>
<td>hotel_id: </td>
<td> <input name="hotel_id" type="text" value='$rows[hotel_id]' size=45 /> </td>
</tr>
<tr>
<td>start_date: </td>
<td> <input name="start_date" type="text" value='$rows[start_date]'size=45> </td>
</tr>
<tr>
<td>end_date: </td>
<td> <input name="end_date" type="text" value='$rows[end_date]'size=45> </td>
</tr>
<tr>
<td>content: </td>
<td> <input name="animal" type="text" value='$rows[news_date]'size=45> </td>
</tr>
<tr>
<td>source: </td>";
<td> <input name="source" type="text" value='$rows[source]'size=45> </td>
</tr>
<tr>
<td>s_type:</td>
<td> <input name="s_type" type="text" value="$rows[s_type]"> </td>
</tr>
<tr>
<td> </td>
<td> <input name="submit" type="submit" value="用户更新"> <input name="fanhui" type="button" value="返回" onClick="window.open ('index_baocun.php')"></td>
</tr>

</table>

该怎么写啊
...全文
1004 点赞 收藏 11
写回复
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
haihao_110 2010-08-03
这是我编辑后台代码:
<?php
$db_host="127.0.0.1:3306";
$db_user="root";
$db_psw="";
$db_name="mysql";
$connection=mysql_connect($db_host,$db_user,$db_psw)or die("连接服务器失败");
mysql_select_db($db_name,$connection)or die("选择数据库失败");
//从数据库里去数据
$hid = !empty($_GET['hid'])?intval($_GET['hid']):0;
$sql = "SELECT * FROM hotel_activities_2 where hid='.$hid'";
$result2=mysql_query($sql) or die("查询失败");
$hotel_id=$_GET['hotel_id'];
$start_date=$_GET['start_date'];
$end_date=$_GET['end_date'];
$content=$_GET['content'];
$source=$_GET['source'];
$s_type=$_GET['s_type'];

$MySql_update=mysql_query("update hotel_activities_2 set hotel_id='$hotel_id',start_date='$start_date',end_date='$end_date',content='$content',source='$source',s_type='$s_type' where h_id='$hid");
$result=mysql_query($MySql_update);
echo mysql_errno();
if ($result) {
echo '数据更新成功!';
}else {
echo '数据更新失败!';
}
//更新结束
?>
回复
haihao_110 2010-08-03
[Quote=引用 8 楼 jianglin28290 的回复:]
你在输出之前总得先查询数据库吧
[/Quote]
$sql = "SELECT * FROM hotel_activities_2 where hid='.$hid'"; 
$result2=mysql_query($sql) or die("查询失败");
回复
jianglin28290 2010-08-03
你在输出之前总得先查询数据库吧
回复
CunningBoy 2010-08-03
要类似这样去取值
while($result=mysql_query($MySql_update)){
echo $result['colum_name'];
};
多看看PHP手册:
http://www.php.net/manual/en/function.mysql-query.php
回复
haihao_110 2010-08-03
[Quote=引用 4 楼 amani11 的回复:]
PHP code

//up_load.php
$hid = !empty($_GET['hid']) ? intval($_GET['hid']) : 0;

$sql = "SELECT * FROM "……………………" WHERE hid=" . $hid;

//把数据搜索出来。。。没有找到的时候,参数非法
//否则,对应的input里,显示对应的值
[/Quote]
$sql = "SELECT * FROM hotel_activities_2 where hid='.$hid'"; 
$result2=mysql_query($sql) or die("查询失败");
//$hid = !empty($_GET['hid'])?intval($_GET['hid']):0;
$hotel_id=$_GET['hotel_id'];
$start_date=$_GET['start_date'];
$end_date=$_GET['end_date'];
$content=$_GET['content'];
$source=$_GET['source'];
$s_type=$_GET['s_type'];
$MySql_update=mysql_query("update hotel_activities_2 set hotel_id='$hotel_id',start_date='$start_date',end_date='$end_date',content='$content',source='$source',s_type='$s_type' where h_id='$hid");
$result=mysql_query($MySql_update);
echo mysql_errno();
if ($result) {
echo '数据更新成功!';
}else {
echo '数据更新失败!';
}

??
回复
haihao_110 2010-08-03
楼上的大侠们
为什么文本框中没有值啊
<form action="upedit.php" method="get">
<table border=1 height=100 width=400 align="center">
<tr>
<td>hotel_id: </td>
<td> <input name="hotel_id" type="text" value='<?php $rows[hotel_id]; ?>' size=45 /> </td>
</tr>
<tr>
<td>start_date: </td>
<td> <input name="start_date" type="text" value='<?php $rows[start_date];?>'size=45> </td>
</tr>
<tr>
<td>end_date: </td>
<td> <input name="end_date" type="text" value='<?php $rows[end_date];?>'size=45> </td>
</tr>
<tr>
<td>content: </td>
<td> <input name="animal" type="text" value='<?php $rows[news_date];?>'size=45> </td>
</tr>
<tr>
<td>source: </td>";
<td> <input name="source" type="text" value='<?php $rows[source];?>'size=45> </td>
</tr>
<tr>
<td>s_type:</td>
<td> <input name="s_type" type="text" value='<?php $rows[s_type];?>' size=45> </td>
</tr>
<tr>
<td> </td>
<td> <input name="submit" type="submit" value="用户更新"> <input name="fanhui" type="button" value="返回" onClick="window.open ('index_baocun.php')"></td>
</tr>

</table></form>

这是upedit.php
<?php
$db_host="127.0.0.1:3306";
$db_user="root";
$db_psw="";
$db_name="mysql";
$connection=mysql_connect($db_host,$db_user,$db_psw)or die("连接服务器失败");
mysql_select_db($db_name,$connection)or die("选择数据库失败");
//从数据库里去数据
$hid = !empty($_GET['hid'])?intval($_GET['hid']):0;
$hotel_id=$_GET['hotel_id'];
$start_date=$_GET['start_date'];
$end_date=$_GET['end_date'];
$content=$_GET['content'];
$source=$_GET['source'];
$s_type=$_GET['s_type'];
$MySql_update=mysql_query("update hotel_activities_2 set hotel_id='$hotel_id',start_date='$start_date',end_date='$end_date',content='$content',source='$source',s_type='$s_type' where h_id='$hid");
$result=mysql_query($MySql_update);
echo mysql_errno();
if ($result) {
echo '数据更新成功!';
}else {
echo '数据更新失败!';
}
//更新结束
?>
回复
amani11 2010-08-03

//up_load.php
$hid = !empty($_GET['hid']) ? intval($_GET['hid']) : 0;

$sql = "SELECT * FROM "……………………" WHERE hid=" . $hid;

//把数据搜索出来。。。没有找到的时候,参数非法
//否则,对应的input里,显示对应的值
回复
jianglin28290 2010-08-03
你也可以把html当做字符串输出
回复
caizhuguanguan 2010-08-03
[Quote=引用楼主 haihao_110 的回复:]
通过第一页的按钮

PHP code
<a href="up_load.php?hid=' . $row['h_id'] . '">编辑</a>
,在第二页获取选定的值,并把值传递到第二页input中

HTML code
<table border=1 height=100 width=400 align="center">
<tr>
<td>hotel_i……
[/Quote]
顶啊顶
回复
CunningBoy 2010-08-03
类似这样:
<input name="hotel_id" type="text"  value='<?php $rows[hotel_id]; ?>' size=45 />
回复
haihao_110 2010-08-03
大侠们帮帮忙吧
这是我改后的编辑后台
$db_host="127.0.0.1:3306";
$db_user="root";
$db_psw="";
$db_name="mysql";
$connection=mysql_connect($db_host,$db_user,$db_psw)or die("连接服务器失败");
mysql_select_db($db_name,$connection)or die("选择数据库失败");
//从数据库里去数据
$hid = !empty($_GET['hid'])?intval($_GET['hid']):0;
$sql = "SELECT * FROM hotel_activities_2 where hid='.$hid'";
/*$result2=mysql_query($sql) or die("查询失败");
$hotel_id=$_GET['hotel_id'];
$start_date=$_GET['start_date'];
$end_date=$_GET['end_date'];
$content=$_GET['content'];
$source=$_GET['source'];
$s_type=$_GET['s_type']; */
while($result=mysql_query($sql)){
echo $result['hotel_id'];
echo $result['start_date'];
echo $result['end_date'];
echo $result['content'];
echo $result['source'];
echo $result['s_type'];
};

$MySql_update="update hotel_activities_2 set hotel_id='$hotel_id',start_date='$start_date',end_date='$end_date',content='$content',source='$source',s_type='$s_type' where h_id='$hid";
$result=mysql_query($MySql_update);
echo mysql_errno();
if ($result) {
echo '数据更新成功!';
}else {
echo '数据更新失败!';
}

前台是:
<form action="upedit.php" method="get">
<table border=1 height=100 width=400 align="center">
<tr>
<td>hotel_id:</td>
<td> <input name="hotel_id" type="text" value='<?php $rows[hotel_id]; ?>' size=45 /> </td>
</tr>
<tr>
<td>start_date:</td>
<td> <input name="start_date" type="text" value='<?php $rows[start_date];?>'size=45/> </td>
</tr>
<tr>
<td>end_date: </td>
<td> <input name="end_date" type="text" value='<?php $rows[end_date];?>'size=45/> </td>
</tr>
<tr>
<td>content: </td>
<td> <input name="animal" type="text" value='<?php $rows[news_date];?>'size=45/> </td>
</tr>
<tr>
<td>source: </td>
<td> <input name="source" type="text" value='<?php $rows[source];?>'size=45/> </td>
</tr>
<tr>
<td>s_type:</td>
<td> <input name="s_type" type="text" value='<?php $rows[s_type]; ?>' size=45/> </td>
</tr>
<tr>
<td> </td>
<td> <input name="submit" type="submit" value="用户更新"/> <input name="fanhui" type="button" value="返回" onClick="window.open ('index_baocun.php')"/></td>
</tr>

</table>
</form>

我通过按钮<a href="up_load.php?hid=' . $row['h_id'] . '">编辑</a>来传值
回复
发动态
发帖子
基础编程
创建于2007-09-28

2.1w+

社区成员

从PHP安装配置,PHP入门,PHP基础到PHP应用
申请成为版主
社区公告
暂无公告