Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Content-Type: text/html; charset=utf-8');
- $hostname='localhost';
- $username='root';
- $password='';
- try {
- $dbh = new PDO("mysql:host=$hostname;dbname=edustart;charset=utf8",$username,$password);
- $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
- //echo '<em>Connected to Database</em><br><br>';
- }
- catch(PDOException $e)
- {
- echo $e->getMessage();
- }
- if(isset($_POST["query"]))
- {
- $output = '';
- $query = "SELECT * FROM edu_schools WHERE school_name LIKE '%".$_POST["query"]."%' AND school_type = 'vgs'";
- $sql = $dbh->prepare($query);
- $sql->execute();
- $output = '<ul>';
- $numrows = $sql->rowCount();
- if($numrows > 0)
- {
- while($row = $sql->fetch(PDO::FETCH_ASSOC))
- {
- $output .= '<li>'.$row["school_name"].'</li>';
- }
- }
- else
- {
- $output .= '<li>Finner ikke skolen</li>';
- }
- $output .= '</ul>';
- echo $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement