1
我正在为一个项目制作一个表单,当用户插入他们的用户名并点击提交时,他们的信息将显示在受尊重的区域(带有一些ajax)。问题是数据只显示列名,其余显示为空。我已经插入了表中所需的所有信息,但仍然没有显示数据。 下面是我的PHP代码:PHP/SQL:来自数据库的数据不会显示
<?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>
谁能告诉我什么是错误或者一些解决方案。谢谢
旁注:你真的引用了这些'
@ Fred-ii-那我该怎么用? – Nexz
我不明白你在问什么; “用”什么?我只给了你一个“旁注”,它不完全针对解决你的问题。如果你有错误,你应该检查它们。 –