-
Notifications
You must be signed in to change notification settings - Fork 0
/
newpuzzle.php
164 lines (135 loc) · 6.06 KB
/
newpuzzle.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<?php
require('dbconfig.php');
require('Validate.php');
session_start();
?>
<html>
<head>
<title> New Puzzle </title>
<link rel="stylesheet" type="text/css" href="stylesheets/crate.css">
</head>
<body class="login">
<div id="main">
<div id="header">
<header class="wrapper clearfix">
<div class="center">
<h1 class="title">CRA</h1>
<img src="bobcat1.gif" alt="" />
<img src="boxtarget3inverse.png" alt="" />
<h1 class="title"> </h1>
<h1 class="title">GAM</h1>
<img src="boxtarget3inverse.png" alt="" />
</div>
</header>
</div>
<nav class="navigation">
<ul>
<li><a href="index.php" class="list">Home</a></li>
<li><a href="puzzlelist.php" class="list">Puzzle List</a></li>
<?php
if(isset($_SESSION['name']))
{
echo '<li><a href="logout.php" class="login">' . "Logout" . '</a></li>' ;
echo '<li class="username">' .'Logged in as user: '. $_SESSION['name'] . '</li>' ;
}
else
{
echo '<li><a href="registration.php" class="registration">Registration</a></li>' ;
echo '<li><a href="login.php" class="login">Login</a></li>';
}
?>
</ul>
</nav>
<?php
//$name = "";
$newpuzname = "";
if(count($_POST) > 0)
{
//$name = $_POST['name'] ;
$newpuzname = $_POST['newpuzname'] ;
$recname = $_SESSION['name'] ;
$connect = mysqli_connect($server, $user, $pass, $db);
if(!$connect)
{
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$sql = "Select puzname from puzzles where puzname = '$newpuzname' " ;
$result = $connect->query($sql);
if(!$result)
{
die("Could not query Database" . $mysqli->error);
}
else
{
if($result->num_rows > 0 )
{
$err["newpuzname"] = true ;
}
else
{
header("Location: crategame.php?seed=" . 0 . "&recscore=" . 0 . "&puzname=" . $newpuzname);
}
}
if(isset($err))
{
//$fields = implode(',',array()ray_keys($err));
foreach ($err as $key => $value) {
if($key == 'newpuzname')
{
echo '<div class="errorbox error"><span>error: </span>Puzzle name already exist please add new puzzle name</div>';
}
}
}
}
?>
<div id="container3">
<div id="container2">
<div id="container1">
<div id="col1">
</div>
<div id="col2">
<div>
<?php
if(isset($_SESSION['name']))
{
unset($_SESSION['newpuz']);
if($_SERVER['REQUEST_METHOD'] === "GET" || isset($err))
{
if(count($_POST) > 0 )
{
//$name = $_POST['name'] ;
$newpuzname = $_POST['newpuzname'] ;
}
else
{
//$name = "" ;
$newpuzname = "" ;
}
?>
<form method="post" class="smart-green" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" enctype="multipart/form-data">
<h1>New Puzzle Name <span>Please add name and submit.</span></h1>
<p><label for="name"><span>PuzzleName:*</span></label>
<input class="input" type="text" name="newpuzname" placeholder="testpuzzle" value="<?php print $newpuzname ?>"></p>
<p><input class="submit" type="submit" namprint $namee="submit" value="Submit"></p>
</form>
<?php
}
}
else
{
$_SESSION['newpuz'] = 'redirect';
header("Location: login.php");
}
?>
</div>
</div>
<div id="col3">
</div>
</div>
</div>
</div>
</div>
</body>
</html>