Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CollegeBusTrackingSystem
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
6
Issues
6
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
External Wiki
External Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
KLUGLUG
CollegeBusTrackingSystem
Commits
f967d4f9
Unverified
Commit
f967d4f9
authored
Apr 27, 2018
by
Manideep2897
Committed by
GitHub
Apr 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
php files
parent
8c10a066
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
163 additions
and
0 deletions
+163
-0
klu5/src/newfile.php
klu5/src/newfile.php
+121
-0
klu5/src/retrive.php
klu5/src/retrive.php
+42
-0
No files found.
klu5/src/newfile.php
0 → 100644
View file @
f967d4f9
<?php
header
(
'Access-Control-Allow-Origin:*'
);
// Define database connection parameters
$hn
=
'localhost'
;
$un
=
'root'
;
$pwd
=
''
;
$db
=
'klubus'
;
$cs
=
'utf8'
;
// Set up the PDO parameters
$dsn
=
"mysql:host="
.
$hn
.
";port=3306;dbname="
.
$db
.
";charset="
.
$cs
;
$opt
=
array
(
PDO
::
ATTR_ERRMODE
=>
PDO
::
ERRMODE_EXCEPTION
,
PDO
::
ATTR_DEFAULT_FETCH_MODE
=>
PDO
::
FETCH_OBJ
,
PDO
::
ATTR_EMULATE_PREPARES
=>
false
,
);
// Create a PDO instance (connect to the database)
$pdo
=
new
PDO
(
$dsn
,
$un
,
$pwd
,
$opt
);
// Retrieve the posted data
$json
=
file_get_contents
(
'php://input'
);
$obj
=
json_decode
(
$json
);
$key
=
strip_tags
(
$obj
->
key
);
// Determine which mode is being requested
switch
(
$key
)
{
// Add a new record to the technologies table
case
"create"
:
// Sanitise URL supplied values
$latitude
=
filter_var
(
$obj
->
latitude
,
FILTER_SANITIZE_NUMBER_FLOAT
,
FILTER_FLAG_ALLOW_FRACTION
);
$longitude
=
filter_var
(
$obj
->
longitude
,
FILTER_SANITIZE_NUMBER_FLOAT
,
FILTER_FLAG_ALLOW_FRACTION
);
// Attempt to run PDO prepared statement
try
{
$sql
=
"INSERT INTO routes (LATITUDE, LONGITUDE) VALUES(:LATITUDE, :LONGITUDE)"
;
$stmt
=
$pdo
->
prepare
(
$sql
);
$stmt
->
bindParam
(
':LATITUDE'
,
$latitude
);
$stmt
->
bindParam
(
':LONGITUDE'
,
$longitude
);
$stmt
->
execute
();
echo
json_encode
(
array
(
'message'
=>
'Congratulations the record '
.
$latitude
.
' was added to the database'
));
}
// Catch any errors in running the prepared statement
catch
(
PDOException
$e
)
{
echo
$e
->
getMessage
();
}
break
;
// Update an existing record in the technologies table
case
"update"
:
$NAME
=
filter_var
(
$obj
->
NAME
,
FILTER_SANITIZE_STRING
,
FILTER_FLAG_ENCODE_LOW
);
$MOBILE
=
filter_var
(
$obj
->
MOBILE
,
FILTER_SANITIZE_NUMBER_INT
);
$PASSWORD
=
filter_var
(
$obj
->
PASSWORD
,
FILTER_SANITIZE_STRING
,
FILTER_FLAG_ENCODE_LOW
);
$SHOPNAME
=
filter_var
(
$obj
->
SHOPNAME
,
FILTER_SANITIZE_STRING
,
FILTER_FLAG_ENCODE_LOW
);
$CATEGORY
=
filter_var
(
$obj
->
CATEGORY
,
FILTER_SANITIZE_STRING
,
FILTER_FLAG_ENCODE_LOW
);
$LOCATION
=
filter_var
(
$obj
->
LOCATION
,
FILTER_SANITIZE_NUMBER_INT
);
$recordID
=
filter_var
(
$obj
->
recordID
,
FILTER_SANITIZE_NUMBER_INT
);
// Attempt to run PDO prepared statement
try
{
$sql
=
"UPDATE register SET NAME = :NAME, MOBILE = :MOBILE,PASSWORD=:PASSWORD,SHOPNAME=:SHOPNAME,CATEGORY=:CATEGORY,LOCATION=:LOCATION WHERE sno = :recordID"
;
$stmt
=
$pdo
->
prepare
(
$sql
);
$stmt
->
bindParam
(
':NAME'
,
$NAME
,
PDO
::
PARAM_STR
);
$stmt
->
bindParam
(
':MOBILE'
,
$MOBILE
,
PDO
::
PARAM_INT
);
$stmt
->
bindParam
(
':PASSWORD'
,
$PASSWORD
,
PDO
::
PARAM_STR
);
$stmt
->
bindParam
(
':SHOPNAME'
,
$SHOPNAME
,
PDO
::
PARAM_STR
);
$stmt
->
bindParam
(
':CATEGORY'
,
$CATEGORY
,
PDO
::
PARAM_STR
);
$stmt
->
bindParam
(
':LOCATION'
,
$LOCATION
,
PDO
::
PARAM_INT
);
$stmt
->
bindParam
(
':recordID'
,
$recordID
,
PDO
::
PARAM_INT
);
$stmt
->
execute
();
echo
json_encode
(
'Congratulations the record '
.
$NAME
.
' was updated'
);
}
// Catch any errors in running the prepared statement
catch
(
PDOException
$e
)
{
echo
$e
->
getMessage
();
}
break
;
// Remove an existing record in the technologies table
case
"delete"
:
// Sanitise supplied record ID for matching to table record
$recordID
=
filter_var
(
$obj
->
recordID
,
FILTER_SANITIZE_NUMBER_INT
);
// Attempt to run PDO prepared statement
try
{
$pdo
=
new
PDO
(
$dsn
,
$un
,
$pwd
);
$sql
=
"DELETE FROM technologies WHERE id = :recordID"
;
$stmt
=
$pdo
->
prepare
(
$sql
);
$stmt
->
bindParam
(
':recordID'
,
$recordID
,
PDO
::
PARAM_INT
);
$stmt
->
execute
();
echo
json_encode
(
'Congratulations the record '
.
$NAME
.
' was removed'
);
}
// Catch any errors in running the prepared statement
catch
(
PDOException
$e
)
{
echo
$e
->
getMessage
();
}
break
;
}
?>
klu5/src/retrive.php
0 → 100644
View file @
f967d4f9
<?php
// Define database connection parameters
$hn
=
'localhost'
;
$un
=
'root'
;
$pwd
=
''
;
$db
=
'klubus'
;
$cs
=
'utf8'
;
// Set up the PDO parameters
$dsn
=
"mysql:host="
.
$hn
.
";port=3306;dbname="
.
$db
.
";charset="
.
$cs
;
$opt
=
array
(
PDO
::
ATTR_ERRMODE
=>
PDO
::
ERRMODE_EXCEPTION
,
PDO
::
ATTR_DEFAULT_FETCH_MODE
=>
PDO
::
FETCH_OBJ
,
PDO
::
ATTR_EMULATE_PREPARES
=>
false
,
);
// Create a PDO instance (connect to the database)
$pdo
=
new
PDO
(
$dsn
,
$un
,
$pwd
,
$opt
);
$data
=
array
();
// Attempt to query database table and retrieve data
try
{
$stmt
=
$pdo
->
query
(
'SELECT LATITUDE, LONGITUDE FROM routes '
);
while
(
$row
=
$stmt
->
fetch
(
PDO
::
FETCH_OBJ
))
{
// Assign each row of data to associative array
$data
[]
=
$row
;
}
// Return data as JSON
echo
json_encode
(
$data
);
}
catch
(
PDOException
$e
)
{
echo
$e
->
getMessage
();
}
?>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment