【悬赏255财富】html调用php读取mysql数据,返回显示在html页面的问题。

【悬赏255财富】html调用php读取mysql数据,返回显示在html页面的问题。,第1张

html  需jq支持

<header>

<meta http-equiv="Content-Type" content="text/html charset=utf-8">

<script type="text/javascript" src="jsfile/jquery-1.10.2.min.js"></script>

<script type="text/javascript">

$(document).ready(function(){

//$("#tel").val("123")

$("#dk_search").click(function(){

var key = $("#keyword").val() 

var data = "uname="+key 

//alert(data)

$.get("./k.php",data, function(text){ 

alert(text)

$("#tel").val(text) 

}) 

})

})

</script>

</header>

<body>

<label for="keyword" width="40">用户名</label>

<input type="text" name="keyword" id="keyword" size="15" value=""/></br>

<label for="tel" width="40" >电  话</label>

<input type="text" id="tel" size="15" value="" /></br>

<input type="submit" id="dk_search" value="读取" > 

</body> k.php

<?php

header("Content-Type: text/html charset=utf-8")

 $mysqli=new mysqli("127.0.0.1", "root", "123456", "testmysql") //数据库 mysqli对象

   if(mysqli_connect_error()){     // 

            $this->error = mysqli_connect_error()  

            echo mysqli_connect_error()

return FALSE  

    }  

$mysqli->query("SET NAMES UTF8")

if(!isset($_GET['uname']) || $_GET['uname']=="" ){

echo "请输入用户名"

return

}

$uname= $_GET['uname']

$sql="select tel from `yonghubiao` where  name='$uname' top 1 "

$rs=$mysqli->query($sql)

$row = $rs->fetch_array(MYSQL_ASSOC)

echo $row['tel']

?>

引入文件  jq

一看你就是刚学习的菜鸟,没必要写两个sql语句,$sql = 'select user_id,user_name form user_list'查询出来赋值给变量$user然后遍历$user

foreach($user as $value){

echo '<option value="'.$value['user_id'].'">'.$value['user_name'].'</option>'

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5905537.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-07
下一篇 2023-03-07

发表评论

登录后才能评论

评论列表(0条)

保存