Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new item #262

Merged
merged 1 commit into from
Aug 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions WAD Form Test/data/se_1505658_student.sql
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 */;
18 changes: 18 additions & 0 deletions WAD Form Test/se_1505658.sql
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]");
30 changes: 30 additions & 0 deletions WAD Form Test/se_1505658_form.php
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>
1 change: 1 addition & 0 deletions WAD Form Test/se_1505658_index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php include 'se_1505408_form.php' ?>
56 changes: 56 additions & 0 deletions WAD Form Test/se_1505658_insert.php
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;
}

?>
9 changes: 9 additions & 0 deletions WAD Form Test/se_1505658_style.css
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;
}