-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql2.0.php
40 lines (35 loc) · 888 Bytes
/
sql2.0.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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php
$servername = "localhost";
$username = "sid";
$password = "temp";
$dbname = "usadb";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
echo "Connection Successful!";
}
$state = $_POST["state"];
$sql = "SELECT * FROM city where state = '$state';";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "zipcode: " . $row["zipcode"]. " - Name: " . $row["name"]. " " . " - State: " . $row["state"]. " " ." - County: " . $row["county"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
</body>
</html>