Notice: Undefined index: q in C:\xampp\htdocs\getuser.php on line 3

<?php

$q = $_GET["q"];

$con = mysqli_connect('localhost','huang','681021','mydb');
if (!$con)
{
die('Could not connect: ' . mysqli_error($con));
}

mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM person WHERE id = '".$q."'";

$result = mysqli_query($con,$sql);

echo "<table border='1'>
<tr>
<th>firstname</th>
<th>lastname</th>
<th>age</th>
<th>hometown</th>
<th>job</th>
</tr>";

while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['firstName'] . "</td>";
echo "<td>" . $row['lastName'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "<td>" . $row['hometown'] . "</td>";
echo "<td>" . $row['job'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?>

怎么解决

感觉不需要单引号,id是整数类型,不是字符类型
$sql="SELECT * FROM person WHERE id = ".$q;
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网