Skip to content

Instantly share code, notes, and snippets.

@aurorapar
Created November 14, 2016 22:27
Show Gist options
  • Save aurorapar/915efeda9f68f3d9a80cfb02e22ed812 to your computer and use it in GitHub Desktop.
Save aurorapar/915efeda9f68f3d9a80cfb02e22ed812 to your computer and use it in GitHub Desktop.
var url = "http://localhost/lab8/php/driver.php";
window.onload = init;
function init()
{
$("#submitselect").click(submitQuery);
}
function submitQuery(event)
{
var country = $('#countryselect').val();
var city = $('#cityselect').val();
var population = $('#popselect').val();
$.ajax({
type: "POST",
url: url,
data: "country="+country+"&city="+city+"&population="+population,
success: function(response)
{
alert("Returned " + response);
$('#result').html(response);
}
});
}
<?php
$country = $_POST['country'];
# $city = $_POST['city'];
# $population = $_POST['population'];
echo 'rawr';
function getServerSetting($connection, $table, $setting)
{
// Will only work for single attribute, not SELECT *
$setting = $connection->query("SELECT $setting FROM $table");
foreach($setting as $result)
{
return $result[0];
}
}
function sqlConnect($server, $db, $user, $pass)
{
if(!isset($pass))
{
$pass="";
}
try
{
return new PDO("mysql:dbname=$db;host=$server",
$user, $pass
);
}
catch (PDOException $e)
{
echo 'Connection failed: ' . $e->getMessage();
}
}
?>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>World Data</title>
<link href="styles/styles.css" media="all" rel="Stylesheet" type="text/css" />
<script src="js/driver.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<?php include('php/driver.php');?>
</head>
<body>
<header>
</header>
<h1>Make a selection</h1>
<form id="formselect">
Country: <input id="countryselect" type="text" name="country" placeholder="United States">
<br><br>
City: <input id="cityselect" type="text" name="city" placeholder="Chicago">
<br><br>
Population: <input id="popselect" type="text" name="population" placeholder="1000000">
<br>
<p>
<input id="submitselect" type="submit">
</form>
<div id="result"></div>
<footer>
</footer>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment