-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathadddog.php
More file actions
67 lines (59 loc) · 1.98 KB
/
adddog.php
File metadata and controls
67 lines (59 loc) · 1.98 KB
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
<?php
require_once "db.php";
session_start();
if ( isset($_POST['dogname']) && isset($_POST['birthyear'])
&& isset($_POST['weight'])) {
$n = mysql_real_escape_string($_POST['name']);
$e = mysql_real_escape_string($_POST['email']);
$p = mysql_real_escape_string($_POST['password']);
if ( !$_POST['name'] || !$_POST['email'] || !$_POST['password'] ) {
$_SESSION['error'] = 'Please enter information in each field';
header( 'Location: index.php');
return;
}
$sql = "INSERT INTO dogs (dogname, birthyear, weight)
VALUES ('$n', '$e', '$p')";
mysql_query($sql);
$_SESSION['success'] = 'Record Added';
header( 'Location: index.php' ) ;
return;
}
?>
<h1>Add a Dog</h1>
<p>Please give us some information about your dog</p>
<form method="post">
<p>Name:
<input type="text" name="dogname">
</p>
<p>Birth Year:
<input type="int" name="birthyear">
<p>Weight:
<?
$query="SELECT id,weight from weight";
$result = mysql_query ($query);
echo "<select name=weight value=''>Weight</option>";
// printing the list box select command
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[id]>$nt[weight]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
?>
<p>Breed:
<?
$query="SELECT id,breed from breed order by breed";
/* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */
$result = mysql_query ($query);
echo "<select name=breed value=''>Breed</option>";
// printing the list box select command
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[id]>$nt[breed]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
?>
<p>If your dog's breed is not listed, please select "Other"</p>
</p>
<input type="submit" value="Continue"/>
<a href="index.php">Cancel</a></p>
</form>