This repository has been archived by the owner on Dec 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aa
- Loading branch information
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
$host = "localhost"; | ||
$database = "carros"; | ||
$usuario = "root"; | ||
$senha = ""; | ||
|
||
$mysqli = new mysqli($host, $usuario, $senha, $database); | ||
|
||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
include('conexao.php'); | ||
?> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Barra de busca</title> | ||
</head> | ||
<body> | ||
<form action=""> | ||
<input name="busca" value="<?php if(isset($_GET['busca'])) echo $_GET['busca']; ?>" placeholder="Digite os termos de pesquisa" type="text"> | ||
<button type="submit">Pesquisar</button> | ||
</form> | ||
<br> | ||
<table width="500px" border="1"> | ||
<tr> | ||
<th>Marca</th> | ||
<th>Modelo</th> | ||
<th>Ano</th> | ||
</tr> | ||
<?php | ||
if (!isset($_GET['busca'])) { | ||
?> | ||
<tr> | ||
<td colspan="3">Digite algo para pesquisar</td> | ||
</tr> | ||
<?php | ||
} else { | ||
$pesquisa = $mysqli->real_escape_string($_GET['busca']); | ||
$sql_code = "SELECT * FROM veiculos WHERE fabricante LIKE '%$pesquisa%' OR modelo LIKE '%$pesquisa%' OR ano LIKE '%$pesquisa%'"; | ||
$sql_query = $mysqli->query($sql_code) or die("ERRO ao consultar! " . $mysqli->error); | ||
|
||
if ($sql_query->num_rows == 0 or $pesquisa == '') { | ||
?> | ||
<tr> | ||
<td colspan="3">Nenhum resultado encontrado</td> | ||
</tr> | ||
<?php | ||
} else { | ||
while($dados = $sql_query->fetch_assoc()) { | ||
?> | ||
<tr> | ||
<td><?php echo $dados['fabricante']; ?></td> | ||
<td><?php echo $dados['modelo']; ?></td> | ||
<td><?php echo $dados['ano']; ?></td> | ||
</tr> | ||
<?php | ||
} | ||
} | ||
|
||
} ?> | ||
</table> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
-- phpMyAdmin SQL Dump | ||
-- version 5.2.0 | ||
-- https://www.phpmyadmin.net/ | ||
-- | ||
-- Host: localhost:3306 | ||
-- Generation Time: Sep 02, 2023 at 09:39 PM | ||
-- Server version: 8.0.30 | ||
-- PHP Version: 8.2.9 | ||
|
||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; | ||
START TRANSACTION; | ||
SET time_zone = "+00:00"; | ||
|
||
|
||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | ||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | ||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | ||
/*!40101 SET NAMES utf8mb4 */; | ||
|
||
-- | ||
-- Database: `carros` | ||
-- | ||
|
||
-- -------------------------------------------------------- | ||
|
||
-- | ||
-- Table structure for table `veiculos` | ||
-- | ||
|
||
CREATE TABLE `veiculos` ( | ||
`id` int NOT NULL, | ||
`fabricante` varchar(150) NOT NULL, | ||
`modelo` varchar(150) NOT NULL, | ||
`ano` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; | ||
|
||
-- | ||
-- Dumping data for table `veiculos` | ||
-- | ||
|
||
INSERT INTO `veiculos` (`id`, `fabricante`, `modelo`, `ano`) VALUES | ||
(1, 'Volkswagen', 'Gol', '2005'), | ||
(2, 'Ferrari', 'Vermelho', '2022'); | ||
|
||
-- | ||
-- Indexes for dumped tables | ||
-- | ||
|
||
-- | ||
-- Indexes for table `veiculos` | ||
-- | ||
ALTER TABLE `veiculos` | ||
ADD PRIMARY KEY (`id`); | ||
|
||
-- | ||
-- AUTO_INCREMENT for dumped tables | ||
-- | ||
|
||
-- | ||
-- AUTO_INCREMENT for table `veiculos` | ||
-- | ||
ALTER TABLE `veiculos` | ||
MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3; | ||
COMMIT; | ||
|
||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | ||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | ||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; |