index.html
=====================================================
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<!-- <link href="lib/ionic/css/ionic.css" rel="stylesheet">-->
<link href="http://code.ionicframework.com/1.3.1/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="starter">
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Ionic Blank Starter</h1>
</ion-header-bar>
<ion-content ng-controller="productScan">
<form ng-submit="sendinfo()" >
Enter your ID:<input id="id" type="text" name="id" value="2" ng-model="data.id">
<input type="submit" value="Search by ID" name="submit" class="button button-royal">
</form>
<input ng-click="showall()" type="submit" value="Show all" name="submit" class="button button-positive">
<p>{{id}}</p>
<p>{{myTxt}}</p>
<b ng-bind="response"></b>
<table>
<tr ng-repeat="x in names">
<td>ID: {{ x.id }} </td><td> </td>
<td>TITLE: {{ x.title }} </td>
</tr>
</table>
<h3>UPDATE EVENTS TABLE</h3>
<form ng-submit="update()" >
Enter your ID:<input name="id" type="text" name="id" value="2" ng-model="data.updateid"><br/>
Enter your TITLE: <input name="title" type="text" name="title" value="" ng-model="data.updatetitle">
<input type="submit" value="UPDATE" name="submit" class="button button-positive">
</form>
<p>{{updated_label}}</p>
</ion-content>
</ion-pane>
</body>
</html>
query.php
====================================================
<?php
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
$mysql_host = "localhost";
$mysql_database = "myevents";
$mysql_user = "root";
$mysql_password = "";
// Create connection
$conn = new mysqli($mysql_host, $mysql_user, $mysql_password,$mysql_database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
}
// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers:{$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
exit(0);
}
$postdata = file_get_contents("php://input");
if (isset($postdata)) {
$request = json_decode($postdata);
$username = $request->id;
if ($username != "") {
$sql = "SELECT id,title FROM events where id=$username";
$result = $conn->query($sql);
$outp = "";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
$outp .= '{"id":"' . $rs["id"] . '",';
$outp .= '"title":"' . $rs["title"] . '"}';
}
$outp ='{ "records":[ '.$outp.' ]}';
$conn->close();
echo($outp);
}
else {
//echo "Empty username parameter!";
}
}
else {
echo "Not called properly with username parameter!";
}
?>
update.php
=====================================================================
<?php
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
$mysql_host = "localhost";
$mysql_database = "myevents";
$mysql_user = "root";
$mysql_password = "";
// Create connection
$conn = new mysqli($mysql_host, $mysql_user, $mysql_password,$mysql_database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
}
// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers:{$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
exit(0);
}
$postdata = file_get_contents("php://input");
if (isset($postdata)) {
$request = json_decode($postdata);
$eventsid_var = $request->eventsid;
$title_var = $request->eventstitle;
if ($eventsid_var != "" && $title_var !="") {
echo $eventsid_var." ".$title_var;
$sql = "update events set title='".$title_var."' where id=$eventsid_var";
$result = $conn->query($sql);
}
}
else {
echo "Not called properly with username parameter!";
}
?>
=====================================================
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<!-- <link href="lib/ionic/css/ionic.css" rel="stylesheet">-->
<link href="http://code.ionicframework.com/1.3.1/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="starter">
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Ionic Blank Starter</h1>
</ion-header-bar>
<ion-content ng-controller="productScan">
<form ng-submit="sendinfo()" >
Enter your ID:<input id="id" type="text" name="id" value="2" ng-model="data.id">
<input type="submit" value="Search by ID" name="submit" class="button button-royal">
</form>
<input ng-click="showall()" type="submit" value="Show all" name="submit" class="button button-positive">
<p>{{id}}</p>
<p>{{myTxt}}</p>
<b ng-bind="response"></b>
<table>
<tr ng-repeat="x in names">
<td>ID: {{ x.id }} </td><td> </td>
<td>TITLE: {{ x.title }} </td>
</tr>
</table>
<h3>UPDATE EVENTS TABLE</h3>
<form ng-submit="update()" >
Enter your ID:<input name="id" type="text" name="id" value="2" ng-model="data.updateid"><br/>
Enter your TITLE: <input name="title" type="text" name="title" value="" ng-model="data.updatetitle">
<input type="submit" value="UPDATE" name="submit" class="button button-positive">
</form>
<p>{{updated_label}}</p>
</ion-content>
</ion-pane>
</body>
</html>
app.js
=========================================================
var app = angular.module('starter', ['ionic']);
app.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
});
app.controller('productScan', function($scope, $http,$ionicLoading,$timeout,$ionicPopup) {
/*============Update query=================*/
$scope.update = function()
{
var link = 'http://localhost/update.php';
$ionicLoading.show({
duration: 3000,
noBackdrop: true,
template:'<ion-spinner icon="lines"></ion-spinner>'
}).then(function(){
console.log("The loading indicator is now displayed");
});
$http.post(link, {eventsid : $scope.data.updateid,eventstitle:$scope.data.updatetitle}).then(function (res){
$scope.updated_label = "Done";
$scope.updated_label=res.data;
$ionicLoading.hide();
});
}
/*==========Show all query=================*/
$scope.showall = function()
{
$ionicLoading.show({
duration: 3000,
noBackdrop: true,
template:'<ion-spinner icon="lines"></ion-spinner>'
}).then(function(){
console.log("The loading indicator is now displayed");
});
var link = 'http://localhost/selectquery.php';
$http.get(link).success(function (response) {$scope.names = response.records;});
}
/*==========Send And get Data=================*/
$scope.sendinfo = function()
{
$ionicPopup.show({
title: 'Are you sure?',
subTitle: '',
scope: $scope,
buttons: [
{ text: 'Cancel' },
{
text: '<b>OK</b>',
type: 'button-positive',
onTap: function(e) {
if (!$scope.data.id) {
//don't allow the user to close unless he enters wifi password
e.preventDefault();
} else {
return $scope.data.wifi;
}
}
}
]});
var link = 'http://localhost/query.php';
if($scope.data.id=="")
{
$scope.myTxt="Empty Data";
}
else{
$scope.myTxt="";
}
$http.post(link, {id : $scope.data.id}).then(function (res){
$scope.names = res.data.records;
});
// $http({
// method: 'post',
// url: "http://localhost/query.php",
// data: $.param({'id' : $scope.id }),
// headers: {'Content-Type': 'application/x-www-form-urlencoded'}
// }).then(function (response) {
//
// $scope.myTxt=$scope.id;
// window.alert($scope.myTxt);
// $scope.names = response.data.records;
// });
}
//$http.get("http://localhost/query.php",{id : $scope.id})
//.success(function (response) {$scope.names = response.records;});
//.then(function (response) {$scope.names = response.data.records;});
});
query.php
====================================================
<?php
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
$mysql_host = "localhost";
$mysql_database = "myevents";
$mysql_user = "root";
$mysql_password = "";
// Create connection
$conn = new mysqli($mysql_host, $mysql_user, $mysql_password,$mysql_database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
}
// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers:{$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
exit(0);
}
$postdata = file_get_contents("php://input");
if (isset($postdata)) {
$request = json_decode($postdata);
$username = $request->id;
if ($username != "") {
$sql = "SELECT id,title FROM events where id=$username";
$result = $conn->query($sql);
$outp = "";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
$outp .= '{"id":"' . $rs["id"] . '",';
$outp .= '"title":"' . $rs["title"] . '"}';
}
$outp ='{ "records":[ '.$outp.' ]}';
$conn->close();
echo($outp);
}
else {
//echo "Empty username parameter!";
}
}
else {
echo "Not called properly with username parameter!";
}
?>
update.php
=====================================================================
<?php
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
$mysql_host = "localhost";
$mysql_database = "myevents";
$mysql_user = "root";
$mysql_password = "";
// Create connection
$conn = new mysqli($mysql_host, $mysql_user, $mysql_password,$mysql_database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
}
// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers:{$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
exit(0);
}
$postdata = file_get_contents("php://input");
if (isset($postdata)) {
$request = json_decode($postdata);
$eventsid_var = $request->eventsid;
$title_var = $request->eventstitle;
if ($eventsid_var != "" && $title_var !="") {
echo $eventsid_var." ".$title_var;
$sql = "update events set title='".$title_var."' where id=$eventsid_var";
$result = $conn->query($sql);
}
}
else {
echo "Not called properly with username parameter!";
}
?>