Skip to content

Instantly share code, notes, and snippets.

@brendanmckenzie
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brendanmckenzie/4febad97964f3e3bbcdd to your computer and use it in GitHub Desktop.
Save brendanmckenzie/4febad97964f3e3bbcdd to your computer and use it in GitHub Desktop.
<?php
if (isset($_POST['submit'])) {
$user = '...';
$pass = '...';
$dbh = new PDO('mysql:host=xxx;port=xxx;dbname=xxx', $user, $pass);
$stm = $dbh->prepare('insert into customer ( name, email, dob, last_updated ) values ( :name, :email, :dob, current_timestamp )');
$stm->bindParam(':name', $_POST['name']);
$stm->bindParam(':email', $_POST['email']);
$stm->bindParam(':dob', $_POST['dob']);
$stm->execute();
$id = $dbh->lastInsertId();
$stm = $dbh->prepare('insert into address ( customer_id, address, city, postcode ) values ( :customer_id, :address, :city, :postcode )');
$stm->bindParam(':customer_id', $id);
$stm->bindParam(':address', $_POST['address']);
$stm->bindParam(':city', $_POST['city']);
$stm->bindParam(':postcode', $_POST['postcode']);
header('Location: index.php');
exit(0);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hello, Kevin.</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<form action="index.php" method="post">
Name: <input name="name" /><br />
Email: <input name="email" type="email" /><br />
Address: <input name="address" /><br />
Date of Birth: <input name="dob" type="date" /><br />
City: <input name="city" /><br />
Postcode: <input name="postcode" /><br />
<input type="hidden" name="submit" value="true" />
<button type="submit">Save</button>
</form>
</body>
</html>
create table customer (
id integer not null primary key auto_increment,
name varchar(100) not null,
email varchar(100),
dob date,
last_updated datetime );
create table address (
id integer not null primary key auto_increment,
customer_id integer not null foreign key references customer ( id ),
address varchar(100),
city varchar(50),
postcode char(4) );
body, input, button {
font-family: 'Helvetica', sans-serif;
}
input {
background-color: pink;
}
Technologies tested.
PHP5
MySQL
HTML5
CSS
Javascript/JQuery
GIT
Linux
CREDENTIALS:
Server IP: xxxxxx
Server username:xxxx
SSH: Use xxxxx.pem file supplied
MysQL database name: xxxxx
MySQL login and password: xxxxxxxxxx
At the end of each task, submit to the GIT repository
1) HTML5 (30 mins)
Create a page named index.php with a form which submits to the same page.
The form elements are:
Name
Email
Address
Date of Birth
City
Postcode.
All fields are required with the exception of Date of Birth.
2) CSS ( 20 mins )
Set the default font for the page to Helvetica, sans-serif
Add CSS style of your own choosing to style the form.
3) Javascript (30 mins )
Add a javascipt/jquery-ui confirm dialog box to the form.
4) MySQL (20 mins)
Design a schema.sql containing two tables:
Table Name: customer.
Fields: id
name
email
dob
last_updated.
The id field is the primary key.
The dob field is the Date Of Birth of the customer.
Table Name: address
Fields: id
customer id
address
city
postcode
The id field is the primary key
The customer_id fields is a Foreign Key to the customer table.
5) Create a PHP script to put the form variables into the database.
Form data is to be validated and errors displayed where applicable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment