-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditform.php
86 lines (72 loc) · 2.05 KB
/
editform.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
<?php
include_once('lib/head.php');
include_once('lib/include.php');
?>
<body>
<?php include_once('lib/navbar.php');?>
<!-- Page Content -->
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="well">
<?php
$result = db_query("SELECT * FROM `forms` WHERE id={$_GET['id']} LIMIT 1");
while ($row = $result->fetch_assoc()) {
?>
<form class="form-horizontal" action="editform.php" method="get">
<fieldset)>
<!-- Text input-->
<div class="form-group">
<label class="col-md-2 control-label" for="Name">Name</label>
<div class="col-md-10">
<input id="name" name="name" type="text" value="<?php echo $row['form-name']; ?>" placeholder="" class="form-control input-md" required="">
</div>
</div>
<!-- Textarea -->
<div class="form-group">
<label class="col-md-2 control-label" for="form">Form</label>
<div class="col-md-10">
<textarea class="form-control" id="form" name="form" rows="20"><?php echo $row['form']; ?></textarea>
</div>
</div>
<!-- Hidden ID input -->
<input type='hidden' name='id' value="<?php echo $row['id']; ?>">
<!-- Button -->
<div class="form-group">
<label class="col-md-2 control-label" for="submit"></label>
<div class="col-md-10">
<button id="submit" name="submit" class="btn btn-success">Update</button>
</div>
</div>
</fieldset>
</form>
<?php
}
?>
</div>
</div>
</div>
</div>
<?php
if(isset($_GET['submit'])) {
editForm();
}
function editForm() {
$id = db_quote($_GET['id']);
$name = db_quote($_GET['name']);
$form = db_quote($_GET['form']);
/* Remove whitespaces */
$formshort = str_replace(' ', '', $name);
$result = db_query("UPDATE `forms` SET `form-name` = ".$name.", `form` = ".$form.", `formshort` = ".$formshort." WHERE `forms`.`id` = ".$id."");
if($result === false) {
$error = db_error();
// Handle failure - log the error, notify administrator, etc.
} else {
// We successfully inserted a row into the database
echo "<meta http-equiv=\"refresh\" content=\"0;URL=listforms.php\">";
}
}
?>
<!-- Page Content end here -->
</body>
</html>