note 129237 added to ref.mysql
| From: | Anonymous at main dot php dot net | Date: | Mon, 12 Feb 2024 22:44:51 +0000 |
| Subject: | note 129237 added to ref.mysql | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221191@lists.php.net to get a copy of this message | ||
<?php
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$search_term = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Sanitize input
$search_term = mysqli_real_escape_string($conn, $_POST["search_term"]);
// Your SQL query here (modify according to your database schema)
$sql = "SELECT id, name, email FROM users WHERE name LIKE '%$search_term%' OR
email LIKE '%$search_term%'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo
"<table><tr><th>ID</th><th>Name</th><th>Email</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo
"<tr><td>".$row["id"]."</td><td>".$row["name"]."</td><td>".$row["email"]."</td></tr>";
}
echo "</table>";
} else {
echo "No records found matching the search term: $search_term";
}
$conn->close();
}
?>
In this example:
Replace "your_username", "your_password", and "your_database" with
your actual database credentials.
Modify the SQL query in the $sql variable according to your database schema and the condition you
want to search for.
This script retrieves records from the users table where the name or email matches the provided
search term (from a form submission).
Ensure that you have a form in your HTML that submits a POST request to this PHP script with a field
named search_term.
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.131 (proxied: 110.174.220.202)
----
Manual Page -- https://php.net/manual/en/ref.mysql.php
Edit -- https://main.php.net/note/edit/129237
Del: integrated -- https://main.php.net/note/delete/129237/integrated
Del: useless -- https://main.php.net/note/delete/129237/useless
Del: bad code -- https://main.php.net/note/delete/129237/bad+code
Del: spam -- https://main.php.net/note/delete/129237/spam
Del: non-english -- https://main.php.net/note/delete/129237/non-english
Del: in docs -- https://main.php.net/note/delete/129237/in+docs
Del: other reasons-- https://main.php.net/note/delete/129237
Reject -- https://main.php.net/note/reject/129237
Search -- https://main.php.net/manage/user-notes.php