PHP Veritabanı Tablosunda veri Arama

Forum Sayfası
$aranan=$_POST['aranan'];
    //echo $aranan;
$query = $db->query("SELECT * FROM menuler where m_ad LIKE '%$aranan%'", PDO::FETCH_ASSOC);
if ( $query->rowCount() ){
     foreach( $query as $row ){
  	?>
    <li class="nav-item">
      <a class="nav-link" href=<?php echo "'".$row['m_yol']."'"; ?>><?php echo $row['m_ad']; ?></a>
    </li>
    <?php 
 }
}

Listeleme koduyla aynı içeriğe sahip olan aramada listelemeden farklı olarak bir form text’i ve bu text’den alınan verinin

<?php 
try{ // VERI TABANINA BAGLANMA
  $db = new PDO("mysql:host=localhost;dbname=menu", "root", "");
  $db->query("SET CHARACTER SET utf8");
} 
catch ( PDOException $e ){
  print $e->getMessage();
} //BITIS
 

?>
<!DOCTYPE html>
<html>
<head>
	<title></title>
	<meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
</head>
<body>
	<form  method="post">
    <label>Site Url: </label><input type="text" name="url">
    <label>Link Ad: </label><input type="text" name="ad">
    <input type="submit" name="kaydet">
     <label>Ara</label><input type="text" name="aranan">
    <input type="submit" name="">
  </form>
  <form method="post">
   
  </form>
	<?php  error_reporting(0);

$url=$_POST['url'];
$ad=$_POST['ad'];
if(isset($_POST['kaydet'])){//VERI TABANI VERI EKLEME
  try{ 
  $sql = "INSERT INTO menuler (m_ad, m_yol)
  VALUES ('$ad','$url')";
  // use exec() because no results are returned
  $db->exec($sql);
  
}

  catch(PDOException $e){
    echo $sql . "<br>" . $e->getMessage();
  }
}//BITIS

	?>
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
  <!-- Brand/logo -->
  <a class="navbar-brand" href="#">Anasayfa</a>
  <!-- Links -->
  <ul class="navbar-nav">
  	<?php 
$aranan=$_POST['aranan'];
    //echo $aranan;
$query = $db->query("SELECT * FROM menuler where m_ad LIKE '%$aranan%'", PDO::FETCH_ASSOC);
if ( $query->rowCount() ){
     foreach( $query as $row ){
  	?>
    <li class="nav-item">
      <a class="nav-link" href=<?php echo "'".$row['m_yol']."'"; ?>><?php echo $row['m_ad']; ?></a>
    </li>
    <?php 
 }
}
    ?>
  </ul>
</nav>

</body>
</html>

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir