forked from fosscell/payasam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcl_edit.php
65 lines (58 loc) · 1.67 KB
/
cl_edit.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
<?php
// This page handles edit college name requests.
require_once("config.php");
session_start();
if (isset($_SESSION["type"])) {
if ($_SESSION["type"] != 'CL') {
exit("Please go back and try again!");
}
} else {
header("Location: $start_page");
exit();
}
if (isset($_GET['id'])) // request received
$id=$_GET['id'];
else if (isset($_POST['id']) && isset($_POST['name'])) { // Update button clicked from this page
$id=$_POST['id'];
$name=$_POST['name'];
} else
exit("Invalid request!");
if (!preg_match('/^[0-9]+$/',$id))
exit("Invalid request!!!");
$mysqli = new mysqli($host,$db_user,$db_password,$db_name);
if ($mysqli->connect_errno)
die("Connect failed: ".$mysqli->connect_error);
$u_stat = 0;
if ($name) {
$name = $mysqli->real_escape_string($name);
if ($mysqli->query("UPDATE colleges SET name='$name' WHERE id='$id'"))
$u_stat = 1;
}
$result = $mysqli->query("SELECT * FROM colleges WHERE id='$id'");
$row = $result->fetch_assoc();
$result->free();
$mysqli->close();
if ($row)
$name = $row['name'];
else
exit("Invalid college id!");
?>
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>College List</title>
<script type="text/javascript" src="scripts/jquery.min.js"></script>
</head>
<body>
<h1>College List</h1>
<a href="cl.php">Back to list</a>
<a href="logout.php">Log out</a>
<form action="cl_edit.php" method="POST">
<?php if ($u_stat == 1) echo "Successfully updated!<br/>"; ?>
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<input type="text" name="name" value="<?php echo $name; ?>" style="width:320px" />
<input type="submit" value="Update" />
</form>
</body>
</html>