-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
171 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
-- phpMyAdmin SQL Dump | ||
-- version 4.7.4 | ||
-- https://www.phpmyadmin.net/ | ||
-- | ||
-- Host: 127.0.0.1:3306 | ||
-- Generation Time: Mar 23, 2018 at 08:38 AM | ||
-- Server version: 5.7.19 | ||
-- PHP Version: 7.0.23 | ||
|
||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; | ||
SET AUTOCOMMIT = 0; | ||
START TRANSACTION; | ||
SET time_zone = "+00:00"; | ||
|
||
|
||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | ||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | ||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | ||
/*!40101 SET NAMES utf8mb4 */; | ||
|
||
-- | ||
-- Database: `uecs2094_ptest` | ||
-- | ||
|
||
-- -------------------------------------------------------- | ||
|
||
-- | ||
-- Table structure for table `se_1505408_student` | ||
-- | ||
|
||
DROP TABLE IF EXISTS `se_1505408_student`; | ||
CREATE TABLE IF NOT EXISTS `se_1505408_student` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`studentId` varchar(3) NOT NULL, | ||
`name` varchar(25) NOT NULL, | ||
`email` varchar(30) NOT NULL, | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `studentId` (`studentId`), | ||
UNIQUE KEY `email` (`email`) | ||
) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8; | ||
|
||
-- | ||
-- Dumping data for table `se_1505408_student` | ||
-- | ||
|
||
INSERT INTO `se_1505408_student` (`id`, `studentId`, `name`, `email`) VALUES | ||
(1, '702', 'Aaron Chia', '[email protected]'), | ||
(2, '712', 'Samuel Issac', '[email protected]'), | ||
(3, '777', 'Allia Hassan', '[email protected]'), | ||
(4, '789', 'Vinoth Kumar', '[email protected]'), | ||
(5, '795', 'Daphne Ong', '[email protected]'), | ||
(6, '798', 'Yong Wai Mun', '[email protected]'); | ||
COMMIT; | ||
|
||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | ||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | ||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; |
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 @@ | ||
CREATE TABLE se_1505408_student( | ||
id INT(11) AUTO_INCREMENT PRIMARY KEY, | ||
studentId VARCHAR(3) UNIQUE NOT NULL, | ||
name VARCHAR(25) NOT NULL, | ||
email VARCHAR(30) UNIQUE NOT NULL | ||
); | ||
INSERT INTO se_1505408_student(studentId,name,email) | ||
VALUES ("702", "Aaron Chia", "[email protected]"); | ||
INSERT INTO se_1505408_student(studentId,name,email) | ||
VALUES ("712", "Samuel Issac", "[email protected]"); | ||
INSERT INTO se_1505408_student(studentId,name,email) | ||
VALUES ("777", "Allia Hassan", "[email protected]"); | ||
INSERT INTO se_1505408_student(studentId,name,email) | ||
VALUES ("789", "Vinoth Kumar", "[email protected]"); | ||
INSERT INTO se_1505408_student(studentId,name,email) | ||
VALUES ("795", "Daphne Ong", "[email protected]"); | ||
INSERT INTO se_1505408_student(studentId,name,email) | ||
VALUES ("798", "Yong Wai Mun", "[email protected]"); |
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,30 @@ | ||
<?php require 'se_1505408_insert.php' ?> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<link rel = "stylesheet" type = "text/css" href = "se_1505408_style.css"> | ||
</head> | ||
<body> | ||
<h1>E-Form</h1> | ||
<form method="post" action="se_1505408_form.php"> | ||
<label>Student ID:</label> | ||
<input type="text" name="studentId" pattern="^(0|[1-9][0-9]*)$"> | ||
<br><br> | ||
<label>Name:</label> | ||
<input type="text" name="name" pattern="^[a-zA-Z ]*$"> | ||
<br><br> | ||
<label>Email:</label> | ||
<input type="text" name="email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$"> | ||
<br><br> | ||
<input type="submit" name="submit"> | ||
<br><br> | ||
</form> | ||
<?php if (count($errors) > 0) : ?> | ||
<?php foreach ($errors as $error) : ?> | ||
<p><?php echo $error ?></p> | ||
<?php endforeach ?> | ||
</div> | ||
<?php endif ?> | ||
<?php echo $request ?> | ||
</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 @@ | ||
<?php include 'se_1505408_form.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,56 @@ | ||
<?php | ||
$dbhost = "localhost"; | ||
$dbuser = "root"; | ||
$dbpass = ""; | ||
$dbname = "uecs2094_ptest"; | ||
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname) or die($conn->connect_error); | ||
$errors = []; | ||
$request= ""; | ||
|
||
if(isset($_POST['submit'])) | ||
{ | ||
$studentID = $conn->real_escape_string($_POST['studentId']); | ||
$name = $conn->real_escape_string($_POST['name']); | ||
$email = $conn->real_escape_string($_POST['email']); | ||
$name = test_input($name); | ||
$studentId = test_input($studentID); | ||
$email = test_input($email); | ||
|
||
if(empty($_POST['name'])||empty($_POST['studentId'])||empty($_POST['email'])){ | ||
array_push($errors,"Please fill out this fields"); | ||
} | ||
else{ | ||
$name = $conn->real_escape_string($_POST['name']); | ||
$studentID = $conn->real_escape_string($_POST['studentId']); | ||
$email = $conn->real_escape_string($_POST['email']); | ||
$name = test_input($name); | ||
$studentId = test_input($studentID); | ||
$email = test_input($email); | ||
$user_check_query = "SELECT * FROM se_1505408_student WHERE studentId ='$studentId' OR email='$email' LIMIT 1"; | ||
$result = $conn->query($user_check_query); | ||
if($student = $result->fetch_assoc()){ | ||
if ($student['studentId'] === $studentId) { | ||
array_push($errors, "Student Id already exists"); | ||
} | ||
if ($student['email'] === $email) { | ||
array_push($errors, "Email already exists"); | ||
} | ||
} | ||
if(count($errors) ==0){ | ||
$stmt = $conn->prepare("INSERT INTO se_1505408_student(studentId, name, email) VALUES(?,?,?)"); | ||
$stmt->bind_param("sss",$studentId, $name, $email); | ||
$stmt->execute(); | ||
$request = "The record is entered successfully"; | ||
$conn->close(); | ||
} | ||
} | ||
} | ||
|
||
function test_input($data){ | ||
trim($data); | ||
stripslashes($data); | ||
htmlspecialchars($data); | ||
return $data; | ||
} | ||
|
||
?> |
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,9 @@ | ||
h1{ | ||
text-align:center; | ||
color:blue; | ||
} | ||
|
||
form label{ | ||
font-family: Verdana, Geneva, sans-serif; | ||
font-size: 12px; | ||
} |