根据表单提交显示数据 [英] Show data based on form submission

查看:74
本文介绍了根据表单提交显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在php中有一个mySQL数据库和一个表单页面。我需要根据表单中的用户输入从数据库中检索数据的最佳方法。现在,表单将用户输入限制为他们将事先给出的整数。整数将作为自动增量编号在数据库中,称为代表ID。用户将输入代表ID以显示该代表的信息。



我尝试了几种不同的方法,但未能得到结果。这已持续了大约一个月,我每天都在努力。截至目前,我的表单按照我想要的方式工作,创建数据库,收集数据的提交页面是完美的...唯一的问题是我无法根据用户提取所需的数据输入特定的ID。



提交的代码就是我尝试过的最后一个代码。然而,它之前没有像以前那样有效。任何建议都会非常感激,我真的需要一个方向进入。我完全迷失了这个,我认为相对容易,并且越来越沮丧。提前谢谢。



我的尝试:



< pre lang =PHP> <?php
$ host = ' myhost';
$ user = ' myuser';
$ pass = ' mypassword';
$ db = ' mydatabase';

$ con = mysqli_connect( $ host $ username $ password die( 连接数据库时出错: .mysqli_error());
mysqli_select_db($ con, $ db死(mysqli_error());

$ query = $ _GET [' 查询'];

$ sql = SELECT * FROM'repData'WHERE'repid'= $ query;
$ result = $ con> query($ sql);

if ($ result-> num_rows> 0){
echo ;

while($ row = $ result-> fetch_assoc()){
echo ;
}
echo < ;表>< TBODY>< TR><的第i; ID< /第><的第i;姓名< /第>< / TR>< TR>< TD> $行[ repID]。 < span class =code-string>< / td>< td>。$ row [ repName]。 。$ row [ repBio]。 < / TD>< / TR GT&;< / tbody的>< /表>;
} 其他 {
echo < br>< h1 align = center >很抱歉,我们的数据库中找不到该ID。< br>
验证该号码,然后重试。< / h1>
;
}

$ con> close();
?>

解决方案

host = ' myhost';


user = ' 为myuser';


pass = ' 输入mypassword';


I have a mySQL database and a form page in php. I need the best way to retrieve data from the database based on user input in the form. Now, the form will limit user input to an integer they will be given before hand. The integer will be in the database as an auto increment number that will be called 'rep ID'. The user will input the 'rep ID' to display that rep's information.

I have tried several different approaches, yet have not been able to get a result. This has been ongoing for about a month, with me working on it daily. As of right now, I have the form working the way I want it, the database created, the submission page for collecting the data is perfect... the only problem is I can't manage to pull the data needed based on the user inputting a specific ID.

The code submitted is just the last I have tried. It however, did not work as the several before. Any suggestions would be greatly appreciated, and I just really need a direction to head in. I'm totally lost with this, what I thought was going to be relatively easy, and am growing frustrated. Thank you in advance.

What I have tried:

<?php 
 $host = 'myhost';
 $user = 'myuser';
 $pass = 'mypassword';
 $db = 'mydatabase';

	$con = mysqli_connect("$host", "$username", "$password") or die("Error connecting to database: ".mysqli_error());
	mysqli_select_db($con, "$db") or die(mysqli_error());

    $query = $_GET['query']; 

	$sql = "SELECT * FROM 'repData' WHERE 'repID' = $query";
	$result = $con->query($sql);

	if ($result->num_rows > 0) {
		echo "";

		while($row = $result->fetch_assoc()) {
			echo "";
		}
		echo "<table><tbody><tr><th>ID</th><th>Name</th></tr><tr><td>".$row["repID"]."</td><td>".$row["repName"]." ".$row["repBio"]."</td></tr></tbody></table>";
	} else {
		echo "<br><h1 align="center">Sorry that ID could not be found in our database.<br>
		Verify the number and try again.</h1>";
	}

	$con->close();
	?>

解决方案

host = 'myhost';


user = 'myuser';


pass = 'mypassword';


这篇关于根据表单提交显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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