Skip to content

Commit 1b5c5e2

Browse files
authored
Added Server Files
1 parent eb5d8f6 commit 1b5c5e2

9 files changed

Lines changed: 318 additions & 0 deletions

File tree

Server Files/addTask.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
include('connect.php');
4+
5+
if($_SERVER['REQUEST_METHOD']=='POST')
6+
{
7+
8+
$taskdescription=$_POST['taskdescription'];
9+
$taskname=$_POST['taskname'];
10+
$username=$_POST['username'];
11+
$status=$_POST['status'];
12+
13+
$sql = "INSERT INTO task (name, description, status, username)
14+
VALUES ('$taskname','$taskdescription','$status','$username')";
15+
16+
if ($conn->query($sql) === TRUE)
17+
{
18+
echo mysqli_insert_id($conn);
19+
// Returns the Auto-increment ID generated of the new record
20+
}
21+
else
22+
{
23+
//echo "Error: " . $sql . "<br>" . $conn->error;
24+
}
25+
}
26+
?>

Server Files/connect.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
$servername = "localhost";
4+
$username = "root";
5+
$password = "";
6+
$dbname = "tododb";
7+
8+
$conn = new mysqli($servername, $username, $password, $dbname);
9+
10+
if (mysqli_connect_errno())
11+
{
12+
echo "Failed to connect to database: " . mysqli_connect_error();
13+
}
14+
15+
/*else
16+
{
17+
echo "Connection Established";
18+
}*/
19+
20+
?>

Server Files/deleteTask.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
include('connect.php');
4+
5+
if($_SERVER['REQUEST_METHOD']=='POST')
6+
{
7+
8+
$taskId=$_POST['taskId'];
9+
10+
$sql = "DELETE from task where id = '$taskId'";
11+
12+
if ($conn->query($sql) === TRUE)
13+
{
14+
echo "Task Deleted";
15+
}
16+
else
17+
{
18+
echo "Error: " . $sql . "<br>" . $conn->error;
19+
}
20+
}
21+
?>

Server Files/getTask.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
include('connect.php');
4+
5+
if($_SERVER['REQUEST_METHOD']=='POST')
6+
{
7+
8+
$username=$_POST['username'];
9+
10+
$return_arr = array();
11+
12+
$sql = "SELECT * FROM task where username = '$username'";
13+
14+
$result = mysqli_query($conn,$sql);
15+
16+
$response = array();
17+
18+
while($row = mysqli_fetch_array($result))
19+
{
20+
$temp = array();
21+
$temp['TaskId']=$row['id'];
22+
$temp['TaskName']=$row['name'];
23+
$temp['TaskDescription']=$row['description'];
24+
$temp['status']=$row['status'];
25+
26+
array_push($response,$temp);
27+
}
28+
29+
echo json_encode($response);
30+
}
31+
else
32+
{
33+
echo 'error';
34+
}
35+
?>

Server Files/login.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
include('connect.php');
4+
5+
if($_SERVER['REQUEST_METHOD']=='POST')
6+
{
7+
/*
8+
Getting password as a String is not a good practise.
9+
Instead compute the Hash of the password and use that for comparing.
10+
*/
11+
$username=$_POST['username'];
12+
$password=$_POST['password'];
13+
14+
$sql = "SELECT name FROM user WHERE username = '$username' and password = '$password'";
15+
$result = $conn->query($sql);
16+
17+
if ($result->num_rows > 0) {
18+
19+
while($row = $result->fetch_assoc()) {
20+
echo $row["name"];
21+
}
22+
}
23+
else
24+
{
25+
echo "-1"; // Indicates invalid details
26+
}
27+
}
28+
?>

Server Files/register.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
include('connect.php');
4+
5+
if($_SERVER['REQUEST_METHOD']=='POST')
6+
{
7+
8+
9+
$name=$_POST['name'];
10+
$username=$_POST['username'];
11+
$password=$_POST['password'];
12+
13+
$sql = "INSERT INTO user (username, password, name)
14+
VALUES ('$username','$password','$name')";
15+
16+
if ($conn->query($sql) === TRUE)
17+
{
18+
echo "Registerd Successfully!";
19+
}
20+
else
21+
{
22+
echo "Error: " . $sql . "<br>" . $conn->error;
23+
}
24+
}
25+
?>

Server Files/task.sql

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
-- phpMyAdmin SQL Dump
2+
-- version 4.8.5
3+
-- https://www.phpmyadmin.net/
4+
--
5+
-- Host: 127.0.0.1
6+
-- Generation Time: May 18, 2019 at 02:11 PM
7+
-- Server version: 10.1.39-MariaDB
8+
-- PHP Version: 7.1.29
9+
10+
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
11+
SET AUTOCOMMIT = 0;
12+
START TRANSACTION;
13+
SET time_zone = "+00:00";
14+
15+
16+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
17+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
18+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
19+
/*!40101 SET NAMES utf8mb4 */;
20+
21+
--
22+
-- Database: `tododb`
23+
--
24+
25+
-- --------------------------------------------------------
26+
27+
--
28+
-- Table structure for table `task`
29+
--
30+
31+
CREATE TABLE `task` (
32+
`id` int(11) NOT NULL,
33+
`name` varchar(20) NOT NULL,
34+
`description` varchar(100) NOT NULL,
35+
`status` int(11) NOT NULL,
36+
`username` varchar(10) NOT NULL
37+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
38+
39+
--
40+
-- Dumping data for table `task`
41+
--
42+
43+
INSERT INTO `task` (`id`, `name`, `description`, `status`, `username`) VALUES
44+
(1, 'Go to market', 'get chicken and eggs', 0, 'test1');
45+
46+
--
47+
-- Indexes for dumped tables
48+
--
49+
50+
--
51+
-- Indexes for table `task`
52+
--
53+
ALTER TABLE `task`
54+
ADD PRIMARY KEY (`id`);
55+
56+
--
57+
-- AUTO_INCREMENT for dumped tables
58+
--
59+
60+
--
61+
-- AUTO_INCREMENT for table `task`
62+
--
63+
ALTER TABLE `task`
64+
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=75;
65+
COMMIT;
66+
67+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
68+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
69+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Server Files/updateTask.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
include('connect.php');
4+
5+
if($_SERVER['REQUEST_METHOD']=='POST')
6+
{
7+
8+
$taskId=$_POST['taskId'];
9+
$taskdescription=$_POST['taskdescription'];
10+
$taskname=$_POST['taskname'];
11+
$status=$_POST['status'];
12+
13+
$sql = "UPDATE task SET name = '$taskname', description = '$taskdescription', status = '$status' where id = '$taskId'";
14+
15+
if ($conn->query($sql) === TRUE)
16+
{
17+
echo "Updated Task";
18+
}
19+
else
20+
{
21+
echo "Error: " . $sql . "<br>" . $conn->error;
22+
}
23+
}
24+
?>

Server Files/user.sql

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
-- phpMyAdmin SQL Dump
2+
-- version 4.8.5
3+
-- https://www.phpmyadmin.net/
4+
--
5+
-- Host: 127.0.0.1
6+
-- Generation Time: May 18, 2019 at 02:09 PM
7+
-- Server version: 10.1.39-MariaDB
8+
-- PHP Version: 7.1.29
9+
10+
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
11+
SET AUTOCOMMIT = 0;
12+
START TRANSACTION;
13+
SET time_zone = "+00:00";
14+
15+
16+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
17+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
18+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
19+
/*!40101 SET NAMES utf8mb4 */;
20+
21+
--
22+
-- Database: `tododb`
23+
--
24+
25+
-- --------------------------------------------------------
26+
27+
--
28+
-- Table structure for table `user`
29+
--
30+
31+
CREATE TABLE `user` (
32+
`id` int(11) NOT NULL,
33+
`username` varchar(10) NOT NULL,
34+
`password` varchar(10) NOT NULL,
35+
`name` varchar(10) NOT NULL
36+
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
37+
38+
--
39+
-- Dumping data for table `user`
40+
--
41+
42+
INSERT INTO `user` (`id`, `username`, `password`, `name`) VALUES
43+
(1, 'test', 'test', 'Batman'),
44+
(2, 'test1', 'test1', 'Stan Lee'),
45+
(3, 'messi', 'messi', 'lio');
46+
47+
--
48+
-- Indexes for dumped tables
49+
--
50+
51+
--
52+
-- Indexes for table `user`
53+
--
54+
ALTER TABLE `user`
55+
ADD PRIMARY KEY (`id`);
56+
57+
--
58+
-- AUTO_INCREMENT for dumped tables
59+
--
60+
61+
--
62+
-- AUTO_INCREMENT for table `user`
63+
--
64+
ALTER TABLE `user`
65+
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
66+
COMMIT;
67+
68+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
69+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
70+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

0 commit comments

Comments
 (0)