-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstickypresidents.php
89 lines (81 loc) · 2.32 KB
/
stickypresidents.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Style-Type" content="text/css"/>
<title>sticky</title>
<link href="/library/skin/tool_base.css" type="text/css" rel="stylesheet" media="all"/>
<link href="/library/skin/morpheus-default/tool.css" type="text/css" rel="stylesheet" media="all"/>
<script type="text/javascript" src="/library/js/headscripts.js"></script>
<style>body {
padding: 5px !important;
}</style>
</head>
<body>
<!--
This PHP script was modified based on result.php in McGrath (2012).
It demonstrates how to ...
1) Connect to MySQL.
2) Write a complex query.
3) Format the results into an HTML table.
4) Update MySQL with form input.
By Ron Coleman
-->
<!DOCTYPE html>
<html>
<?php
# If user opened the page without submitting, initialize the fields
if ( $_SERVER[ 'REQUEST_METHOD' ] == 'GET' ) {
$num = "" ;
$fname = "" ;
$lname = "";
}
# Otherwise, user submitted the form, so let's validate
else if ( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' )
{
# Initialize an error array.
$errors = array();
$num = $_POST[ 'num' ] ;
$fname = $_POST[ 'fname' ] ;
$lname = $_POST[ 'lname' ] ;
# Check for a name & email address.
if ( empty( $num ) ) {
$errors[] = 'num' ;
}
else {
$num = trim( $num ) ;
}
if ( empty( $_POST[ 'fname' ] ) ) {
$errors[] = 'fname' ;
}
else {
$fname = trim( $fname ) ;
}
if ( empty( $_POST[ 'lname' ] ) ) {
$errors[] = 'lname' ;
}
else {
$lname = trim( $lname ) ;
}
# Report result.
if( !empty( $errors ) )
{
echo 'Error! Please enter your ' ;
foreach ( $errors as $field ) { echo " - $field " ; }
}
else {
echo "<p>Success! Thanks $num </p>" ;
}
}
# Show the input form with whatever we got for fields
show_form($num,$fname,$lname) ;
# Shows the input form
function show_form($num,$fname,$lname) {
echo '<form action="stickypresidents.php" method="POST">' ;
echo '<p>Number: <input type="text" name="num" value="' . $num . '"> </p> ' ;
echo '<p>First Name: <input type="text" name="fname" value="' . $fname . '"></p>' ;
echo '<p>Last Name: <input type="text" name="lname" value="' . $lname . '"></p>' ;
echo '<p><input type="submit"></p>' ;
echo '</form>' ;
}
?>
</html>