php点击查询匹配数据库 php搜索数据库

如何实现PHP查询数据库,信息匹配成功,跳转页面?

?php

10年积累的网站制作、成都网站制作经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有达茂旗免费网站建设让你可以放心的选择与我们合作。

$localhost = 'localhost';//本地的基本是用localhost

$dbname = 'dbname';//数据库名

$user = 'user';//用户名

$pw = 'pw';//密码

$pdo = new PDO("mysql:host=".$localhost.";dbname=".$dbname."",$user,$pw); 

$pdo-query('set names utf8');

$username = $_POST['username'];

$userpassword = $_POST['userpassword'];

$sql = 'SELECT userpassword FROM `userinf` WHERE `username`="' . $username . '"';

$row = $pdo-query($sql)-fetch();//查询数据库

if($userpassword == $row['userpassword'])

{

@header("Location: http://网址");//配对成功,跳转

}

else

{

exit('不好意思,你的密码不对');

}

/*

就是这么的简单,但是一般的验证用户密码不是这样的,首先一般存数据库里面的密码都是加密的,通常的MD5加密

而且POST提交过来的数据也要过滤一下

*/

?

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""

html xmlns=""

head

meta http-equiv="Content-Type" content="text/html; charset=utf-8" /

title用户登录验证/title

/head

body

form method="POST"

用户名:input name="username" type="text" / | 密码:input name="userpassword" type="password" / | input type="submit" value="提交"

/form

/body

/html

php如何查询数据库表中的数据并显示

这个简单啊!

首页做个前台输入姓名和会员卡信息的页面,我做个简单的页面给你看

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "

html xmlns="

head

meta http-equiv="Content-Type" content="text/html; charset=utf-8" /

title会员查询系统/title

/head

body

form id="form1" name="form1" method="post" action="test.php"

p

label for="name"/label

input type="text" name="name" id="name" /

/p

p

label for="vipid"/label

input type="text" name="vipid" id="vipid" /

/p

p

input type="submit" name="button" id="button" value="查询" /

/p

/form

/body

/html

然后我给你一个test.php的文件代码:

?php

$name    =    trim($_POST['name']);

$vipid    =    trim($_POST['vipid']);

$con = mysql_connect("127.0.0.1","数据库用户名","数据库密码");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

$a    =    mysql_select_db("数据库名字", $con);

$sql    =    "select * from kh_customer where name = '$name' and vipid = '$vipid'";

$result = mysql_query($sql);

while($row = mysql_fetch_array($result))

{

echo $row['name'] . " " . $row['data'];

echo "br /";

}

mysql_close($con);

?

页面美化自己去搞!只能帮你这么多了

用php如何和数据库连接起来,点击查询后查看数据库中的数据

//数据库链接文件

$Link=mysql_connect('localhost','root','');//连接数据库

//返回TRUE/FALSE

if($Link){

$db=mysql_select_db('oa',$Link);

//设置中文编码格式

mysql_query('set names gbk');

if($db){

echo "数据库选择成功!";

}else{

echo "数据库选择失败!错误号:".mysql_error();

}

}else{

echo "连接数据库失败!";

}

php链接数据库 然后再页面上面有 输入ID的文本框 有查询按钮 点击查询按钮 在数据库中查找符合

form action="" method="get"

请输入ID号:input type="text" name="word" /

input type="submit" value="查询" /

/form

?php

if(!($_GET["word"])){

exit();//没有数据

}

mysql_connect("127.0.0.1",用户名,密码);

$sql="use fenzu

select * from think_user

where id={$_GET['word']}

";

$rs=mysql_query($sql);

$num=mysql_num_rows($rs);

//获取影响行数,0表示没查到

if(!($num)){

echo '数据不存在!';

}

$row=mysql_fetch_array($rs);//如果有多条数据请用循环

echo "id:{$row['id']}";

echo "名字:{$row['name']}";

echo "时间:{$row['time']}";

//手机打的没测试过,应该没什么问题

?

php搜索查询数据库

1.action 后面的页面没有指定

2.if($name) 改成 if($name!=‘’)

3.把$sql 打印出来

4.页面报错内容是什么

完善上面4项,纠错毫无压力。

php搜索查询数据库数据

查看一下代码:

?php

// 获取表单提交值

$student_id = intval(trim($_POST['student_id']));

// 页面表单  可以放单独的html文件中,如果放单独的html页面中 form 的action的地址要改成下面的PHP文件名

echo 'form action="" method="post"

input type="text" name="student_id" value="{$student_id}"/

input type="submit" name="submit" value="查询"/

/form';

// 当有数据提交时

if ($student_id)

{

$con= mysql_connect("localhost","root","111") or die("连接错误");

mysql_select_db("examination",$con);

// 查询

$sql = "SELECT * FROM tablename WHERE student_id = $student_id ";

$res=mysql_query($sql);

$row=mysql_fetch_array($res);

// 输出

echo '学号:'.$row['student_id'].'br姓名:'.$row['name'].'br性别:'.$row['gender'].'br分数:'.$row['score'];

}

?


文章名称:php点击查询匹配数据库 php搜索数据库
网站URL:http://ybzwz.com/article/docihgi.html