简体   繁体   English

使用PHP中的表格,我试图返回取决于输入的SQL值的SQL值?

[英]Using a form in PHP, I am trying to return an SQL value dependant on an entered SQL value?

My DB looks like this 我的数据库看起来像这样

paynumber fullname linemanager 薪水全名linemanager
12345 John Smith Jack Jones 12345约翰·史密斯·杰克·琼斯
12346 Joe Bloggs Andy Smith 12346乔·博格斯安迪·史密斯

I want it so if you enter 12345 into a textfield it will return John Smith in the same text field 我想要它,所以如果您在文本字段中输入12345 ,它将在同一文本字段中返回John Smith

I've tried so many mysql_queries I don't know which one to post! 我已经尝试了很多mysql_queries,但我不知道要发布哪一个!

I'm not looking for full code, as I'm not bad at that, but please point me in the right direction! 我不是要查找完整的代码,因为我对此还不错,但是请向我指出正确的方向!

Cheers! 干杯!

    <?php


    $mysql_host = "host"; 
    $mysql_username = "user"; 
    $mysql_password = "pass"; 
    $link = mysql_connect("$mysql_host", "$mysql_username", "$mysql_password");
    mysql_select_db("dbname",$link); 

    $pay_number=intval($_POST["pay_number"]);
    $result = mysql_query($link,"SELECT fullname from officers where paynumber=$pay_number");

    echo $result;

    ?>
SELECT fullname from myTable where paynumber=12345

What's so tough about it? 这有什么难的? Then you can display it anywhere you like. 然后,您可以在任意位置显示它。 Can add a little bit of AJAX to grab the result and show in the same field. 可以添加一点AJAX来抓取结果并显示在同一字段中。

EDIT: 编辑:

Lets say your field on your HTML form was named pay_number and form method was POST 假设您的HTML表单上的字段名为pay_number ,表单方法为POST

Then in your PHP processing code you could do 然后,在您的PHP处理代码中,您可以执行

$pay_number=intval($_POST["pay_number"]);
$query="SELECT fullname from myTable where paynumber=$pay_number";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM