<?php
if (isset($_POST['getData']) and isset($_POST['country']))
{
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "World";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT code, name FROM country where name='" . $_POST['country'] . "';";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $row["code"]. " - " . $row["name"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<form action="" method="post">
Country: <input type="text" name="country">
<input type="submit" name ="getData" value="send"></input>
</form>
</body>
</html>
if (isset($_POST['getData']) and isset($_POST['country']))
{
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "World";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT code, name FROM country where name='" . $_POST['country'] . "';";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $row["code"]. " - " . $row["name"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<form action="" method="post">
Country: <input type="text" name="country">
<input type="submit" name ="getData" value="send"></input>
</form>
</body>
</html>
No comments:
Post a Comment