gpt4 book ai didi

PHP/SQL :Data from DB don't show

转载 作者:行者123 更新时间:2023-11-28 23:17:26 25 4
gpt4 key购买 nike

我正在为一个项目制作一个表单,当用户输入他们的用户名并单击提交时,他们的信息将显示在受尊重的区域(使用一些 ajax)。问题是数据只显示列名,其余的是空的。我已经在表中插入了所有需要的信息,但数据仍然没有出现。下面是我的 PHP 代码:

<?php
require "co.php";
$link = mysqli_connect($h,$u,$p,$db);

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";

$q = "select * from login where User_name ='".$_GET['name']."'";
$result = mysqli_query($link,$q);
if($result){
echo "<table border='1' >
<tr>
<td align=center> <b>user Id No</b></td>
<td align=center><b>Name</b></td>
<td align=center><b>Password</b></td>
<td align=center><b>responsibility</b></td></td>";

while($data = mysql_fetch_row($result))
{
echo "<tr>";
echo "<td align=center>$data[0]</td>";
echo "<td align=center>$data[1]</td>";
echo "<td align=center>$data[2]</td>";
echo "<td align=center>$data[3]</td>";
echo "</tr>";
}
echo "</table>";
}

else{
echo ' Failed';
}
?>

我还包括 html 代码:

html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>

<script type="text/javascript">

$(document).ready(function() {

$("#display").submit(function(e) {
e.preventDefault();

$.ajax({ //create an ajax request to load_page.php
type: "POST",
url: "tesz2.php",
data: { name: $('.name').val() }, // set the naem variable
dataType: "html", //expect html to be returned
success: function(response){
$("#responsecontainer").html(response);
//alert(response);
}

});
});
});

</script>

<body>
<form method =POST action=test2.php id="display">
<input type ="text" class='z' id='name'><br>
<input type='submit'>
</form>


<h3 align="center">Manage Student Details</h3>
<!--table border="1" align="center">
<tr>
<td> <input type="button" id="display" value="Display All Data" /> </td>
</tr>
</table-->
<div id="responsecontainer" align="center">

</div>
</body>

任何人都可以告诉我错误是什么或者一些解决方案。谢谢

最佳答案

添加一个额外的 javascript 函数 displayData() 可用于显示所有数据。

function displayData(){
$.ajax({
url: 'tesz2.php',
type: 'POST',
data:{
'perform': true,
},
success: function(data){
$('#responsecontainer').html(data);
}
});
}

在您的 php 文件中,您必须执行以下操作:

if(isset($_POST['perform'])==true){
//Query........
}

现在添加调用此函数 ajax 函数成功

$.ajax({    //create an ajax request to load_page.php
type: "POST",
url: "tesz2.php",
data: { name: $('#name').val() }, // set the naem variable
dataType: "html", //expect html to be returned
success: function(response){
displayData(); //All data will show
$("#responsecontainer").html(response);
}

});
});
});

关于PHP/SQL :Data from DB don't show,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43244218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com