Php 在输入文本中输入姓名、电子邮件、用户名或D.O.B时,如何显示数据?
Welcome.phpPhp 在输入文本中输入姓名、电子邮件、用户名或D.O.B时,如何显示数据?,php,html,mysqli,Php,Html,Mysqli,Welcome.php <?php session_start(); if (!isset($_SESSION['id'])) { header('location:login.php'); } ?> <!DOCTYPE html> <html> <body> <?php include_once 'connect.php'; $query = mysqli_query($my
<?php
session_start();
if (!isset($_SESSION['id'])) {
header('location:login.php');
}
?>
<!DOCTYPE html>
<html>
<body>
<?php
include_once 'connect.php';
$query = mysqli_query($mysqli, "select * from `users` where userid='" . $_SESSION['id'] . "'");
$row = mysqli_fetch_array($query);
echo 'Welcome - ' . $row['username'];
?>
<br>
<a href="logout.php">Logout</a>
<br><br>
<?php
include_once 'connect.php';
$result = mysqli_query($mysqli, "SELECT * FROM users");
echo "<table border='1'>
<tr>
<th>User_ID</th>
<th>Name</th>
<th>Username</th>
<th>E-mail</th>
<th>Department</th>
<th>Date_of_birth</th>
<th>Age</th>
<th>Image</th>
<th>Action</th>
<th>Action</th>
</tr>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['userid'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['department'] . "</td>";
echo "<td>" . $row['Date_of_birth'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "<td><img alt='image' style='width:100px;height:50px;' src='upload/" . $row['filename'] . "'></td>";
echo "<td> <a href='editform.php?id=" . $row['userid'] . "'>Edit</a></td>";
echo "<td> <a href='deleteform.php?id=" . $row['userid'] . "'>Delete</a></td>";
echo "</tr>";
}
echo "</table>";
include_once 'connect.php';
if (isset($_POST["happy"])) {
if (empty($_POST["happy"])) { //not empty name
echo '<br>';
echo "No letter entered";
} else {
$id = $_GET['id'];
$sql = "SELECT * FROM `users` WHERE userid='$id'";
$result = mysqli_query($mysqli, $sql);
$row = mysqli_fetch_array($result);
$sql = "select name, username, email, Date_of_birth from `users` where (name LIKE '%$name%' OR username LIKE '%$name%' OR email LIKE '%$name%' OR Date_of_birth LIKE '%$name%')";
if (mysqli_query($mysqli, $sql) === TRUE) {
print_r($id);
} else {
echo 'No record found';
}
}
}
?>
<form method="post">
<br>
Search: <input type="text" name="happy"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
我已经更新了你的代码,请尝试一下
<?php
session_start();
if (!isset($_SESSION['id'])) {
header('location:login.php');
}
?>
<!DOCTYPE html>
<html>
<body>
<?php
include_once 'connect.php';
$query = mysqli_query($mysqli, "select * from `users` where userid='" . $_SESSION['id'] . "'");
$row = mysqli_fetch_array($query);
echo 'Welcome - ' . $row['username'];
?>
<br>
<a href="logout.php">Logout</a>
<br><br>
<?php
include_once 'connect.php';
$result = mysqli_query($mysqli, "SELECT * FROM users");
echo "<table border='1'>
<tr>
<th>User_ID</th>
<th>Name</th>
<th>Username</th>
<th>E-mail</th>
<th>Department</th>
<th>Date_of_birth</th>
<th>Age</th>
<th>Image</th>
<th>Action</th>
<th>Action</th>
</tr>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['userid'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['department'] . "</td>";
echo "<td>" . $row['Date_of_birth'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "<td><img alt='image' style='width:100px;height:50px;' src='upload/" . $row['filename'] . "'></td>";
echo "<td> <a href='editform.php?id=" . $row['userid'] . "'>Edit</a></td>";
echo "<td> <a href='deleteform.php?id=" . $row['userid'] . "'>Delete</a></td>";
echo "</tr>";
}
echo "</table>";
include_once 'connect.php';
if (isset($_POST["happy"])) {
if (empty($_POST["happy"])) { //not empty name
echo '<br>';
echo "No letter entered";
} else {
$id = $_GET['id'];
$sql = "SELECT * FROM `users` WHERE userid='$id'";
$result = mysqli_query($mysqli, $sql);
$row = mysqli_fetch_array($result);
$sql = "select name, username, email, Date_of_birth from `users` where (name LIKE '%$name%' OR username LIKE '%$name%' OR email LIKE '%$name%' OR Date_of_birth LIKE '%$name%')";
if (mysqli_query($mysqli, $sql) === TRUE) {
print_r($id);
} else {
echo 'No record found';
}
}
}
?>
<form method="post">
<br>
Search: <input type="text" name="happy"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
<?php
session_start();
if (!isset($_SESSION['id'])) {
header('location:login.php');
}
?>
<!DOCTYPE html>
<html>
<body>
<?php
include_once 'connect.php';
$query=mysqli_query($mysqli,"select * from `users` where userid='".$_SESSION['id']."'");
$row=mysqli_fetch_array($query);
echo 'Welcome - '.$row['username'];
?>
<a href="logout.php">Logout</a>
<?php
//include_once 'connect.php';
$result = mysqli_query($mysqli,"SELECT * FROM users");
echo "<table border='1'>
<tr>
<th>User_ID</th>
<th>Name</th>
<th>Username</th>
<th>E-mail</th>
<th>Department</th>
<th>Date_of_birth</th>
<th>Age</th>
<th>Image</th>
<th>Action</th>
<th>Action</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['userid'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['department'] . "</td>";
echo "<td>" . $row['Date_of_birth'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "<td><img alt='image' style='width:100px;height:50px;' src='upload/".$row['filename']."'></td>";
echo "<td> <a href='editform.php?id=" . $row['userid'] . "'>Edit</a></td>";
echo "<td> <a href='deleteform.php?id=" . $row['userid'] . "'>Delete</a></td>";
echo "</tr>";
}
echo "</table>";
?>
<?php
//include_once 'connect.php';
if(isset($_POST["happy"])){
if(empty($_POST["happy"])){ //not empty name
echo '<br>';
echo "No letter entered";
}else {
$name = $_POST["happy"];
$id = $_GET['id'];
$sql = "SELECT * FROM `users` WHERE userid='$id'";
$result = mysqli_query($mysqli, $sql);
$row = mysqli_fetch_array($result);
$sql="select name, username, email, Date_of_birth from `users` where (name LIKE '%$name%' OR username LIKE '%$name%' OR email LIKE '%$name%' OR Date_of_birth LIKE '%$name%')";
if (mysqli_query($mysqli, $sql) === TRUE) {
print_r($id);
}else {
echo 'No record found';
}
}
}
?>
<form method="post">
<br>
Search: <input type="text" name="happy"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
问题或错误请放在此处注意:未定义索引:id在C:\xampp\htdocs\registration\u form\u 2\welcome.php第78行注意:未定义变量:名称在C:\xampp\htdocs\registration\u form\u 2\welcome.php第82行注意:未定义变量:名称在C:\xampp\htdocs\registration\u form\u 2\welcome.php第82行注意:未定义变量:第82行C:\xampp\htdocs\registration\u form\u 2\welcome.php中的名称注意:未定义变量:第82行C:\xampp\htdocs\registration\u form\u 2\welcome.php中的名称以上错误我得到的第一件事不包括“connect.php”;很多次。我不明白怎么做请帮助我sir注意:未定义的变量:_sessionin C:\xampp\htdocs\registration\u form\u 2\welcome.php第3行注意:未定义的索引:id in C:\xampp\htdocs\registration\u form\u 2\welcome.php第61行请帮助我sir如何做请立即尝试未定义的索引:id in第59行的C:\xampp\htdocs\registration\u form\u 2\welcome.php