当我输入数据库中的用户ID时,我希望它回显/打印来自该用户文件的所有数据。因此,如果我输入" user_id = 2",我希望用户"姓名","年龄"等等。我到了哪里,它给了我一切没有参数。代码:
$link = mysqli_connect("localhost", "root", "");
mysqli_select_db($link, "magicsever");
if(mysqli_connect_error()){
die ("Database connection error");
}
$query = "SELECT * FROM classified_videos";
$result = mysqli_query($link, $query);
while($row = mysqli_fetch_array($result)){
print_r ($row);
}
但我希望来自特定用户,这就是我认为的代码
if(isset($_POST['submit'])){
$link = mysqli_connect("localhost", "root", "");
mysqli_select_db($link, "magicsever");
if(mysqli_connect_error()){
die ("Database connection error");
}
$query = "SELECT * FROM classified_videos WHERE user_id ='".mysqli_real_escape_string($link, $_POST['userid'])."' LIMIT 1";
$result = mysqli_query($link, $query);
while($row = mysqli_fetch_array($result)){
print_r ($row['vid_category_1']);
}
}
?>
<form method="post">
<input type="text" name="userid" placeholder="user id...">
<input type="submit" value="submit">
</form>
答案 0 :(得分:1)
此if(isset($_POST['submit']))
期望提交名为submit
的输入,但您目前仅发送userid
将此name="submit"
添加到您的按钮:
<input type="submit" value="submit" name="submit">