Advertisement
Squito

Kereső

Nov 15th, 2022 (edited)
941
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | Source Code | 0 0
  1. <?php
  2. $conn = new mysqli("localhost","root","","autocomplete_db");
  3. if($conn->connect_error)
  4. {
  5.     //die("Failed to connect!".conn->connect_error); /*csak akkor írass ki prod környezetben ilyesmit ha MUSZÁJ*/
  6.     /*legjobb ha a die-ban egy generikus hibaüzenet van, semmi specifikus*/
  7. }
  8. if(isset($_POST['submit']))
  9. {
  10.     $search='%'.$_POST['search'].'%';
  11.     $prep=mysqli_stmt_init($conn);
  12.     mysqli_stmt_prepare($prep, "SELECT id, country_name, country_code, city FROM countries WHERE country_name LIKE ?"); //ne használ *-ot, csak ha tényleg mindegyik mező kell (erőforrás pazarlás)
  13.     mysqli_stmt_bind_param($prep, "s", $search);
  14.     mysqli_stmt_execute($prep);
  15.     mysqli_stmt_store_result($prep);
  16.     if(mysqli_stmt_num_rows($prep)==1)
  17.     {
  18.         mysqli_stmt_bind_result($prep, $id, $cname, $ccode, $city);
  19.         mysqli_stmt_fetch($prep);
  20.         echo "ID :".$id."<br>";
  21.         echo "Country Name:".$cname."<br>";
  22.         echo "Country Code:".$ccode."<br>";
  23.         echo "City:".$city."<br>";
  24.     }
  25.     else
  26.     {
  27.         echo "Nincs találat";
  28.     }
  29.     mysqli_stmt_close($prep);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement