是否有任何方法可以使用从脚本获取的代码并在php中使用它?

是否有任何方法可以使用从脚本获取的代码并在php中使用它?,php,html,ajax,Php,Html,Ajax,我正在做一个类似livesearch的东西 我的桌子在这 <table> <tr> <th>barcode</th> <th>name</th> </tr> <tr><td><input type="text" id="fk_ColCode" onKeyDown="search()"></td> <td><input type="text" id=

我正在做一个类似livesearch的东西 我的桌子在这

<table>
<tr>
<th>barcode</th>
<th>name</th>
</tr>
<tr><td><input type="text" id="fk_ColCode" onKeyDown="search()"></td>
<td><input type="text" id="fk_ColName" disabled></td></tr>
</table>

条形码
名称
剧本

<script>
function search(){
var barcode=document.getElementById('fk_ColCode').value;
document.getElementById('fk_colName').value = <?php 
$select_1="select colName FROM colacc WHERE ColCode='barcode'";
if($select_2=mysql_query($select_1))
while($select_3=mysql_fetch_array($select_2)) {
print $select_3["colName"]; }?>
}

函数搜索(){
var barcode=document.getElementById('fk_ColCode')。值;

document.getElementById('fk_colName')。value=Sidenote:你应该使用Ajax来实现这一点。像那样注入MySQL,这只会让事情变得更加困难。我认为只需稍加修改即可:D(不确定)您不能在Javascript中调用php代码。您应该使用Ajax请求,如@Fred ii所述,您的用户将请求一个url并获取html/css/Javascript,所有这些都运行客户端。他们的浏览器中不会安装php,您也不会希望他们拥有您的db凭据,这是一种服务器端语言,您的php/mysql就是这样在服务器上。使用ajax将请求发送到另一个php页面,提取值,然后在服务器端执行查询。我不知道ajax是否可以帮助我更改此设置以获取livesearch。