大哥帮帮忙!!!!如何从表单中获取数据并查询 各位大哥帮忙啊,连接的是postgresql数据库,比如有表名为:table ,里面有字段:ID,card,name现在从表单中输入card的值,然后在table中查找card的值并输出该行,各位大哥该怎么弄?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用查询语句select * from table * 代表你要查询的字段,,,可以替换成card name 等得到一个结果集,遍历就可以了!! ??????????http://www.isstudy.com select * from table where card=$_POST['card']试一试吧 1.php<!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><form action="2.php" method="post"><input type="text" name="card" id="card"/><input type="submit" name="submit" ></form></body></html>2.php<!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><div align="center"><table border="2"> <tr> <td>ID </td> <td>card </td> <td>name </td> </tr><?php$card=$_POST["card"];$host="localhost";//数据库地址$user="root";//连接用户名$pwd="";//密码$base="";//数据库名称@$con=mysql_connect($host,$user,$pwd) or die("连接失败");@mysql_select_db($base) or die("数据库名称出错");$sql="select * from table where card='".$card."'";$i=0; while($row = mysql_fetch_array($result)){ ?> <tr> <?php while($i <3){?><td> <?php echo $row[$i];?> </td> <?php $i++;}}?></tr></table></div></body></html> 楼上的大哥,我用的是postgresql数据库,把2.PHP改成:2.PHP------------------------------------------------------------------<!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=GB2312" /> <title> </title> </head> <body> <div align="center"> <table border="2"> <tr> <td>ID </td> <td>card </td> <td>name </td> </tr> <?php $card=$_POST["card"]; $con=pg_connect("host=localhost dbname=BenShop user=postgres password=hainan") or die("连接失败"); if ($con){ echo "连接成功";}//@pg_select_db($base) or die("数据库名称出错"); $sql="select * from table1 where card='".$card."'"; $i=0; while($row = pg_fetch_array($result)){ ?> <tr> <?php while($i <3) {?> <td> <?php echo $row[$i];?> </td> <?php $i++; } }?> </tr> </table> </div> </body> </html>------------------------------------------------------------------------出错情况是:Warning: pg_fetch_array() expects parameter 1 to be resource, null given in D:\wwwroot\2.php on line 32大哥这事什么回事??? PHP 重命名文件的问题 招募创业技术团员 JPGraph细节使用问题,求达人~ ECSHOP中,已有函数如何在模板里使用呢? wordpress 的时间问题 PHP很强大,散分! zendstudio中怎么改还是中文乱码怎么解决呢? php 程序员使用是什么linux系统好呢?? 弱弱的问一下,怎么调用一周新闻? thinkphp 的数据插入为啥是空值啊 求....经典算法 散分!国庆快乐,中秋快乐!
select * from table * 代表你要查询的字段,,,可以替换成card name 等
得到一个结果集,遍历就可以了!!
试一试吧
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> </title>
</head>
<body>
<form action="2.php" method="post">
<input type="text" name="card" id="card"/>
<input type="submit" name="submit" >
</form>
</body>
</html>
2.php<!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>
<div align="center">
<table border="2">
<tr>
<td>ID </td>
<td>card </td>
<td>name </td>
</tr>
<?php
$card=$_POST["card"];$host="localhost";//数据库地址
$user="root";//连接用户名
$pwd="";//密码
$base="";//数据库名称
@$con=mysql_connect($host,$user,$pwd) or die("连接失败");
@mysql_select_db($base) or die("数据库名称出错");$sql="select * from table where card='".$card."'";
$i=0;
while($row = mysql_fetch_array($result)){ ?>
<tr> <?php while($i <3){?>
<td> <?php echo $row[$i];?> </td> <?php $i++;
}
}?>
</tr>
</table>
</div>
</body>
</html>
------------------------------------------------------------------
<!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=GB2312" />
<title> </title>
</head>
<body>
<div align="center">
<table border="2">
<tr>
<td>ID </td>
<td>card </td>
<td>name </td>
</tr>
<?php
$card=$_POST["card"]; $con=pg_connect("host=localhost dbname=BenShop user=postgres password=hainan") or die("连接失败");
if ($con){
echo "连接成功";
}
//@pg_select_db($base) or die("数据库名称出错"); $sql="select * from table1 where card='".$card."'";
$i=0;
while($row = pg_fetch_array($result)){ ?>
<tr> <?php while($i <3)
{?>
<td> <?php echo $row[$i];?> </td> <?php $i++;
}
}?>
</tr>
</table>
</div>
</body>
</html>
------------------------------------------------------------------------
出错情况是:
Warning: pg_fetch_array() expects parameter 1 to be resource, null given in D:\wwwroot\2.php on line 32
大哥这事什么回事???