/
found-1.php
66 lines (51 loc) · 1.59 KB
/
found-1.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
<!--
Report found Item Page
By Kulvinder Lotay and Artur Barbosa
-->
<!DOCTYPE html>
<html>
<?php
# Connect to MySQL server and the database
require( 'includes/connect_db.php' ) ;
# Includes these helper functions
require( 'includes/helpers.php' ) ;
# If user requests item (clicks quick link) make the appropriate GET request from quick links
# Otherwise, user submitted the form, so let's validate
if ($_SERVER[ 'REQUEST_METHOD' ] == 'POST') {
$errors = array();
$desc = trim($_POST['desc']) ;
$location = ($_POST['location']) ;
$owner = '';
$finder = trim($_POST['finder']);
$image_url = trim($_POST['img_url']);
# Validate description
if (!valid_name($desc)){
$errors[] = 'description';
}
# Validate owner/finder email address
if (!valid_name($finder)){
$errors[] = 'finder email address';
#echo '<p style="color:red; font-size:16px;">Please provide a first name.</p>' ;
}
if (!empty($errors)){
echo '<span style="color: red">Error! Please enter</span>' ;
foreach ( $errors as $field ) {
echo '<span style="color: red; font-style: italic;"> - ' . $field . '</span>' ;
}
}
else {
$result = insert_record($dbc, $desc, $location, $owner, $finder, 'found', $image_url) ;
echo "<p>Successfully added $desc into Stuff.</p>" ;
}
}
# Store current page in variable, call show_links and show_records functions using cur_page variable
$cur_page = $_SERVER['PHP_SELF'];
show_links($dbc, $cur_page);
# Show the records
show_page($cur_page, $dbc);
# Display the footer
show_footer();
# Close the connection
mysqli_close( $dbc ) ;
?>
</html>