[PHP-NOTES] note 130167 added to faq.general
[email protected] ("Anonymous")
| Newsgroups | php.notes |
|---|---|
| Message-ID | <[email protected]> |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<title>Document</title>
</head>
<body>
<?php
// Datenbank verbindung
$servername = "mysql";
$username = "root";
$password = "htlkrems";
$dbname = "classicmodels";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>
<?php
// Delete
if(isset($_GET['del'])){
$id = $_GET['del'];
$stmt = $conn->prepare("DELETE FROM customers WHERE customerNumber = :id");
$stmt->bindParam('id', $id);
$stmt->execute();
if ($stmt->rowCount () == 1) {
// check ob das Statement eine Zeile betroffen hat -› Message in die Variable speichern
$msg = "officeCode (($id}) deleted";
}
}
$sql = "SELECT * FROM customers";
$stmt = $conn->prepare($sql);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<div class="container mt-4">
<form method="GET" class="mb-4">
<div class="input-group">
<input type="text" name="search" class="form-control" placeholder="customerName suchen..." value="<?php echo isset($_GET['search']) ? htmlspecialchars($_GET['search']) : ''; ?>">
<button class="btn btn-primary" type="submit">Suchen</button>
<input type="text" name="search1" class="form-control" placeholder="customerNumber suchen..." value="<?php echo isset($_GET['search1']) ? htmlspecialchars($_GET['search1']) : ''; ?>">
<button class="btn btn-primary" type="submit">Suchen</button>
<button class='btn btn-danger' type="button" onclick="window.location.href='test.php'">Reset</button>
</div>
</form>
</div>
<?php
//Search
$search = isset($_GET['search']) ? $_GET['search'] : '';
$search1 = isset($_GET['search1']) ? $_GET['search1'] : '';
$sql = "SELECT * FROM customers WHERE 1=1";
if (!empty($search)) {
$sql .= " AND customerName LIKE :search";
}
if (!empty($search1) && is_numeric($search1)) {
$sql .= " AND customerNumber = :search1";
}
$stmt = $conn->prepare($sql);
if (!empty($search)) {
$stmt->bindValue(':search', "%$search%", PDO::PARAM_STR);
}
if (!empty($search1) && is_numeric($search1)) {
$stmt->bindValue(':search1', $search1, PDO::PARAM_INT);
}
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
if(isset($_GET['customerNumber'])){
$stmt = $conn->query("SELECT * FROM customers ORDER BY customerNumber ASC");
}
if(isset($_GET['customerName'])){
$stmt = $conn->query("SELECT * FROM customers ORDER BY customerName");
}
if(isset($_GET['contactLastName'])){
$stmt = $conn->query("SELECT * FROM customers ORDER BY contactLastName");
}
if(isset($_GET['contactFirstName'])){
$stmt = $conn->query("SELECT * FROM customers ORDER BY contactFirstName");
}
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 193.170.70.42)
----
Manual Page -- https://php.net/manual/en/faq.general.php
Edit -- https://main.php.net/note/edit/130167
Del: integrated -- https://main.php.net/note/delete/130167/integrated
Del: useless -- https://main.php.net/note/delete/130167/useless
Del: bad code -- https://main.php.net/note/delete/130167/bad+code
Del: spam -- https://main.php.net/note/delete/130167/spam
Del: non-english -- https://main.php.net/note/delete/130167/non-english
Del: in docs -- https://main.php.net/note/delete/130167/in+docs
Del: other reasons-- https://main.php.net/note/delete/130167
Reject -- https://main.php.net/note/reject/130167
Search -- https://main.php.net/manage/user-notes.php