Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $conn = new mysqli("localhost","root","","autocomplete_db");
- if($conn->connect_error)
- {
- //die("Failed to connect!".conn->connect_error); /*csak akkor írass ki prod környezetben ilyesmit ha MUSZÁJ*/
- /*legjobb ha a die-ban egy generikus hibaüzenet van, semmi specifikus*/
- }
- if(isset($_POST['submit']))
- {
- $search='%'.$_POST['search'].'%';
- $prep=mysqli_stmt_init($conn);
- 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)
- mysqli_stmt_bind_param($prep, "s", $search);
- mysqli_stmt_execute($prep);
- mysqli_stmt_store_result($prep);
- if(mysqli_stmt_num_rows($prep)==1)
- {
- mysqli_stmt_bind_result($prep, $id, $cname, $ccode, $city);
- mysqli_stmt_fetch($prep);
- echo "ID :".$id."<br>";
- echo "Country Name:".$cname."<br>";
- echo "Country Code:".$ccode."<br>";
- echo "City:".$city."<br>";
- }
- else
- {
- echo "Nincs találat";
- }
- mysqli_stmt_close($prep);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement