-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
77 lines (68 loc) · 2.37 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
if(preg_match("/^[a-z|A-Z]+/", $_POST['name'])){ //check form input is text characters
$name=$_POST['name'];
//create database credentials
$servername = "sql5c25d.carrierzone.com";
$username = "w42renf2sc957916";
$password = "vgy78uhb!";
// Create connection
$dsn = 'mysql:host=sql5c25d.carrierzone.com;dbname=irstationtable_w42renf2sc957916';
$options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);
// connect to database
$db = new PDO($dsn, $username, $password, $options);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // throws PDOException can be caught and handled gracefully if you choose to do so.
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
// echo "Connected successfully";
//-query the database table
$sth = $db->prepare("SELECT ID,StationName,StreamURL FROM Stationpages WHERE StationName LIKE '%" . $name . "%' OR StationType LIKE '%" . $name ."%'");
//-run the query against the mysql query function
$sth->execute();
// echo "<ul>\n Internet Radio search results";
//Return next row as an array indexed by column name
// print("PDO::FETCH_ASSOC: ");
// print("Return next row as an array indexed by column name\n");
$sth->setFetchMode(PDO::FETCH_ASSOC);
}
else{
echo "<p>Please enter a search query</p>";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> search results </title>
<link rel="stylesheet" type="text/css" href="fonts.css" >
<link rel="stylesheet" type="text/css" href="css/styles.css">
</head>
<body>
<header>
Internet Radio Stations
</header>
<nav><strong>Links</strong></nav>
<section>
<p> Internet Radio Search Results </p>
<?php while ($row = $sth->fetch()):?>
<!--<p><?php // echo $row ['LocalURL'];?></p>-->
<p>
<!-- <a href= "<?php //echo $row ['LocalURL']?>"><?php //echo $row['StationName'];?></a> -->
<a href="station.php?id=<?php echo $row['ID']?>"> <?php echo $row['StationName'];?></a>
<a href= "<?php echo $row ['StreamURL']?>"><?php echo "Stream";?></a>
</p>
<?php endwhile; ?>
</section>
<article>
<p> article goes here </p>
</article>
<footer>
<strong> Copyright Warren Earle </strong>
</footer>
</body>
</html>