如何使用用户输入的文本框从Mysql数据库中检索数据? [英] How to retrieve the data from Mysql databse using a textbox input from the user?

查看:119
本文介绍了如何使用用户输入的文本框从Mysql数据库中检索数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在html中创建了一个页面,我在其中放置了一个文本框,用户将在其中提供值,然后将检索与我的mysql数据库中的值相对应的数据。我无法检索数据。



 <  !DOCTYPE     HTML  >  
< html >
< head >
< title > 获取已保存的记录< / title >
< / head < span class =code-keyword>>

< body >
< div class = 容器 >
< div class = displaydetails >
< 表格 方法 = POST action = RetrieveandDisplay.php >
输入搜索数据的名称: < br / >
< 输入 type = text name = FetchDetails >
< 输入 类型 = 提交 名称 = 查找 value = 查找数据 / >
< / form >
< < span class =code-leadattribute> / div
>
< / div >
< / body >
< ; / html >







 <?php  
include(' connectionstring.php');

if(!$ connection)
{
die(' 无法连接到数据库:' .mysql_error());
}

$ inputname = $ _ POST [' 查找' ]。

$ myquery = SELECT * FROM addentry WHERE FirstName ='$ inputname';

$ fetched = mysql_query($ myquery);

while($ rowvalue = mysql_fetch_array($ fetched))
{
$ firstname = $ rowvalue [' < span class =code-string> FirstName'
];
$ middlename = $ rowvalue [' MiddleName'];
$ lastname = $ rowvalue [' LastName'];
$ phone1 = $ rowvalue [' Phone1'];
$ phone2 = $ rowvalue [' Phone2'];
$ email = $ rowvalue [' Email'];
$ address = $ rowvalue [' Address'];
}
mysql_close($ connection);
?>

< html >
< 正文 >
< div class = 容器 >
< div class = 抓取 >
< 表格 >
< label > 名字< / label >
< 输入 < span class =code-attribute> name
= FirstName 类型 = text value =' <?php echo $ firstname; ?>' / >
< 标签 > 中间名< / label >
< 输入 name = MiddleName type = text value =' <?php echo $ middlename; ?>' / >
< 标签 > 姓氏< / label >
< 输入 name = 姓氏 type = text value =' <?php echo $ lastname; ?>' / >
< 标签 > Phone1 < / label >
< input name = Phone1 < span class =code-attribute> type = text value =' <?php echo $ phone1; ?>' / >
< 标签 > Phone2 < / label >
< input name = Phone2 < span class =code-attribute> type = text value =' <?php echo $ phone2; ?>' / >
< 标签 > 电子邮件< / label >
< input name = email < span class =code-attribute> type = text value =' <?php echo $ email; ?>' / >
< 标签 > 地址< / label >
< textarea id = 地址 < span class =code-attribute> name = address1 value =' <?php echo $ address; ?>' > < / textarea >

< / form >
< / div >
< / div >
< / body >
< / html >

解决方案

connection)
{
die(' 不能连接到数据库:'< /跨度> .mysql_error());
}


inputname =


_POST [' 查找];

I have created a page in html where i have placed a textbox and the user will supply the value in it which will then retrieve the data corresponding to the value from my mysql database. I am unable to retrieve the data.

<!DOCTYPE HTML>
<html>
<head>
<title>Fetching saved records</title>
</head>

<body>
<div class="container">
	<div class="displaydetails">
	<form method="POST" action="RetrieveandDisplay.php">
		Enter the name to search data:<br/>
		<input type="text" name="FetchDetails">
		<input type="submit" name="Find" value="Find Data"/>
	</form>
	</div>
</div>
</body>
</html>




<?php
	include('connectionstring.php');
	
	if(!$connection)
	{
		die('Could not connect to database : '.mysql_error());
	}
	
	$inputname=$_POST['Find'];
	
	$myquery="SELECT * FROM addentry WHERE FirstName='$inputname'";
	
	$fetched=mysql_query($myquery);
	
	while($rowvalue=mysql_fetch_array($fetched))
	{
		$firstname=$rowvalue['FirstName'];
		$middlename=$rowvalue['MiddleName'];
		$lastname=$rowvalue['LastName'];
		$phone1=$rowvalue['Phone1'];
		$phone2=$rowvalue['Phone2'];
		$email=$rowvalue['Email'];
		$address=$rowvalue['Address'];
	}
	mysql_close($connection);
?>

<html>
<body>
<div class="container">
<div class="fetched">
<form>
	<label>First Name</label>
	<input name="FirstName" type="text" value='<?php echo $firstname; ?>'/>
	<label>Middle Name</label>
	<input name="MiddleName" type="text" value='<?php echo $middlename; ?>'/>
	<label>Last Name</label>
	<input name="LastName" type="text" value='<?php echo $lastname; ?>'/>
	<label>Phone1</label>
	<input name="Phone1" type="text" value='<?php echo $phone1; ?>'/>
	<label>Phone2</label>
	<input name="Phone2" type="text" value='<?php echo $phone2; ?>'/>
	<label>Email</label>
	<input name="email" type="text" value='<?php echo $email; ?>'/>
	<label>Address</label>
	<textarea id="Address" name="address1" value='<?php echo $address; ?>'></textarea>
	
</form>
</div>
</div>
</body>
</html>

解决方案

connection) { die('Could not connect to database : '.mysql_error()); }


inputname=


_POST['Find'];


这篇关于如何使用用户输入的文本框从Mysql数据库中检索数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆