-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add webserver for future api user validation
- Loading branch information
Jonathan Prado
committed
Apr 2, 2021
1 parent
6c98055
commit cf2229e
Showing
15 changed files
with
325 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM php:7.2.7-fpm-alpine3.7 | ||
RUN apk update; apk upgrade; docker-php-ext-install mysqli; docker-php-ext-enable mysqli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<html> | ||
<head> | ||
<title>Add Data</title> | ||
</head> | ||
|
||
<body> | ||
<button><a href="index.php">Home</a></button> | ||
<br/><br/> | ||
|
||
<form action="add.php" method="post" name="form1"> | ||
<table width="25%" border="0"> | ||
<tr> | ||
<td>Name</td> | ||
<td><input type="text" name="name"></td> | ||
</tr> | ||
<tr> | ||
<td>data1</td> | ||
<td><input type="text" name="data1"></td> | ||
</tr> | ||
<tr> | ||
<td>data2</td> | ||
<td><input type="text" name="data2"></td> | ||
</tr> | ||
<tr> | ||
<td></td> | ||
<td><input type="submit" name="Submit" value="Add"></td> | ||
</tr> | ||
</table> | ||
</form> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<html> | ||
<head> | ||
<title>Add Data</title> | ||
</head> | ||
|
||
<body> | ||
<?php | ||
//including the database connection file | ||
include_once("config.php"); | ||
|
||
if(isset($_POST['Submit'])) { | ||
$name = mysqli_real_escape_string($mysqli, $_POST['name']); | ||
$data1 = mysqli_real_escape_string($mysqli, $_POST['data1']); | ||
$data2 = mysqli_real_escape_string($mysqli, $_POST['data2']); | ||
|
||
// checking empty fields | ||
if(empty($name) || empty($data1) || empty($data2)) { | ||
|
||
if(empty($name)) { | ||
echo "<font color='red'>Name field is empty.</font><br/>"; | ||
} | ||
|
||
if(empty($data1)) { | ||
echo "<font color='red'>Age field is empty.</font><br/>"; | ||
} | ||
|
||
if(empty($data2)) { | ||
echo "<font color='red'>Email field is empty.</font><br/>"; | ||
} | ||
|
||
//link to the previous pdata1 | ||
echo "<br/><a href='javascript:self.history.back();'>Go Back</a>"; | ||
} else { | ||
// if all the fields are filled (not empty) | ||
|
||
//insert data to database | ||
$result = mysqli_query($mysqli, "INSERT INTO users(name,data1,data2) VALUES('$name','$data1','$data2')"); | ||
|
||
//display success messdata1 | ||
echo "<font color='green'>Data added successfully."; | ||
echo "<br/><a href='index.php'>View Result</a>"; | ||
} | ||
} | ||
?> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
$databaseHost = 'mysql'; | ||
$databaseName = 'test'; | ||
$databaseUsername = 'admin'; | ||
$databasePassword = 'admin'; | ||
$databasePort = '3306'; | ||
|
||
$mysqli = mysqli_connect($databaseHost, $databaseUsername, $databasePassword, $databaseName, $databasePort); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
//including the database connection file | ||
include("config.php"); | ||
|
||
//getting id of the data from url | ||
$id = $_GET['id']; | ||
|
||
//deleting the row from table | ||
$result = mysqli_query($mysqli, "DELETE FROM users WHERE id=$id"); | ||
|
||
//redirecting to the display page (index.php in our case) | ||
header("Location:index.php"); | ||
?> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use test; | ||
DROP TABLE IF EXISTS `users`; | ||
CREATE TABLE `users` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`name` varchar(100) NOT NULL, | ||
`data1` varchar(20) DEFAULT NULL, | ||
`data2` varchar(20) DEFAULT NULL, | ||
`data3` varchar(20) DEFAULT NULL, | ||
`data4` varchar(20) DEFAULT NULL, | ||
`data5` varchar(20) DEFAULT NULL, | ||
`data6` varchar(20) DEFAULT NULL, | ||
`data7` varchar(20) DEFAULT NULL, | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1; | ||
|
||
LOCK TABLES `users` WRITE; | ||
INSERT INTO `users` VALUES (1,'test01','test01','test01',NULL,NULL,NULL,NULL,NULL),(2,'test02','test02','test02',NULL,NULL,NULL,NULL,NULL); | ||
UNLOCK TABLES; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
// including the database connection file | ||
include_once("config.php"); | ||
|
||
if(isset($_POST['update'])) | ||
{ | ||
|
||
$id = mysqli_real_escape_string($mysqli, $_POST['id']); | ||
|
||
$name = mysqli_real_escape_string($mysqli, $_POST['name']); | ||
$data1 = mysqli_real_escape_string($mysqli, $_POST['data1']); | ||
$data2 = mysqli_real_escape_string($mysqli, $_POST['data2']); | ||
|
||
// checking empty fields | ||
if(empty($name) || empty($data1) || empty($data2)) { | ||
|
||
if(empty($name)) { | ||
echo "<font color='red'>Name field is empty.</font><br/>"; | ||
} | ||
|
||
if(empty($data1)) { | ||
echo "<font color='red'>data1 field is empty.</font><br/>"; | ||
} | ||
|
||
if(empty($data2)) { | ||
echo "<font color='red'>data2 field is empty.</font><br/>"; | ||
} | ||
} else { | ||
//updating the table | ||
$result = mysqli_query($mysqli, "UPDATE users SET name='$name',data1='$data1',data2='$data2' WHERE id=$id"); | ||
|
||
//redirectig to the display pdata1. In our case, it is index.php | ||
header("Location: index.php"); | ||
} | ||
} | ||
?> | ||
<?php | ||
//getting id from url | ||
$id = $_GET['id']; | ||
|
||
//selecting data associated with this particular id | ||
$result = mysqli_query($mysqli, "SELECT * FROM users WHERE id=$id"); | ||
|
||
while($res = mysqli_fetch_array($result)) | ||
{ | ||
$name = $res['name']; | ||
$data1 = $res['data1']; | ||
$data2 = $res['data2']; | ||
} | ||
?> | ||
<html> | ||
<head> | ||
<title>Edit Data</title> | ||
</head> | ||
|
||
<body> | ||
<a href="index.php">Home</a> | ||
<br/><br/> | ||
|
||
<form name="form1" method="post" action="edit.php"> | ||
<table border="0"> | ||
<tr> | ||
<td>Name</td> | ||
<td><input type="text" name="name" value="<?php echo $name;?>"></td> | ||
</tr> | ||
<tr> | ||
<td>data1</td> | ||
<td><input type="text" name="data1" value="<?php echo $data1;?>"></td> | ||
</tr> | ||
<tr> | ||
<td>data2</td> | ||
<td><input type="text" name="data2" value="<?php echo $data2;?>"></td> | ||
</tr> | ||
<tr> | ||
<td><input type="hidden" name="id" value=<?php echo $_GET['id'];?>></td> | ||
<td><input type="submit" name="update" value="Update"></td> | ||
</tr> | ||
</table> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
holaaa :) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
//including the database connection file | ||
include_once("config.php"); | ||
|
||
//fetching data in descending order (lastest entry first) | ||
$result = mysqli_query($mysqli, "SELECT * FROM users ORDER BY id DESC"); // using mysqli_query instead | ||
?> | ||
|
||
<html> | ||
<head> | ||
<title>Homepage</title> | ||
</head> | ||
|
||
<body> | ||
<button><a href="add.html">Add New Data</a></button><button><a href="localhost:3000" target="_blank">Graph</a></button><br/><br/><br/><br/> | ||
|
||
<table width='80%' border=1> | ||
|
||
<tr bgcolor='#CCCCCC'> | ||
<td>Name</td> | ||
<td>data1</td> | ||
<td>data2</td> | ||
<td>Update</td> | ||
</tr> | ||
<?php | ||
while($res = mysqli_fetch_array($result)) { | ||
echo "<tr>"; | ||
echo "<td>".$res['name']."</td>"; | ||
echo "<td>".$res['data1']."</td>"; | ||
echo "<td>".$res['data2']."</td>"; | ||
echo "<td><button><a href=\"edit.php?id=$res[id]\">Edit</a></button> <button><a href=\"delete.php?id=$res[id]\" onClick=\"return confirm('Are you sure you want to delete?')\">Delete</a></button></td>"; | ||
} | ||
?> | ||
</table> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?php | ||
echo phpinfo(); |
Oops, something went wrong.