Php 在文本框中显示值
我有一个名为tb_app的表,其中包含字段“id”、“name”、“aic”、“batchcode” 示例:字段值“1”、“james”、“0001”、“1” 如果在文本框(名称)中键入james,则其他字段(aic、batchcode)的相应值应显示在文本框中。这可能吗?谁能帮帮我…我是php初学者…拜托 表格编号:Php 在文本框中显示值,php,html,Php,Html,我有一个名为tb_app的表,其中包含字段“id”、“name”、“aic”、“batchcode” 示例:字段值“1”、“james”、“0001”、“1” 如果在文本框(名称)中键入james,则其他字段(aic、batchcode)的相应值应显示在文本框中。这可能吗?谁能帮帮我…我是php初学者…拜托 表格编号: <form method="post"> <input type="text" name="names" id="query" /> <inpu
<form method="post">
<input type="text" name="names" id="query" />
<input type="text" name="aic" />
<input type="text" name="batchcode" />
<input type="submit" name="show" />
</form>
您可以通过Jquery ajax来实现这一点,通过使用您的确切字段名来尝试,这可能会对您有所帮助 jquery脚本应该是这样的
function getvalues()
{
var selname = $("input[name='names']:text"").val();
$.ajax({ url: "getuserdata.php",
data: {"selname":selname},
type: 'post',
success: function(output) {
$("#aic").val(output);
$("#batchcode").val(output);
}
});
}
还有你的Html代码
<input type="text" name="names" id="query" onblur="getvalues()"/>
<input type="text" name="aic" id="aic"/>
<input type="text" name="batchcode" id="batchcode" />
getuserdata.php
<?php
include("database connection file here");
$selname = $_POST['selname'];
$query = "SELECT * FROM table_name WHERE youruser_id = $selname";
$res = mysql_query($query);
$rows = mysql_fetch_array($res);
echo $rows['aic'];
echo $rows['batchcode'];
?>
你可以在names
textbox的模糊事件中使用ajax。尝试此链接可能会对你有所帮助。你的userid是字段名id?因为你在textbox中发布名称,这应该是你在表格中的字段名。当我输入名称时,它不会在相应的文本框中显示aic和batchode?jquery脚本中的selname什么是这个吗?我的表字段名?还是文本框输入名称?脚本中的selname:selname让我感到困惑。