-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcosponsor.php
138 lines (101 loc) · 3.22 KB
/
cosponsor.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
<!DOCTYPE HTML>
<?php
session_start();
if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
header ("Location: login.php");
}
//1. Create a database connection
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "Clubhub";
$mysqli = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
// Test if connection succeeded
if(mysqli_connect_errno()) {
die("Database connection failed: " .
mysqli_connect_error() .
" (" . mysqli_connect_errno() . ")"
);
}
?>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$userid= $_SESSION['userName'];
$eventid = $_POST['eventname'];
$clubname = $_POST['clubname'];
$c_name2 = "";
$eventid2 ="";
if(!($stmt = $mysqli->prepare("SELECT clubid FROM club WHERE clubid = ?"))){
echo "Prepare failed: (" . $mysqli->errno . ")" . $mysqli->error;
}
if(!$stmt->bind_param('s', $clubname)){
echo "Bind failed: (" . $stmt->errno . ")" . $stmt->error;
}
execute query */
$stmt->execute();
/* Store the result (to get properties) */
$stmt->store_result();
/* Get the number of rows */
$num_of_rows = $stmt->num_rows;
/* Bind the result to variables */
$stmt->bind_result($c_name2 );
while ($stmt->fetch()) {}
if(!($stmt = $mysqli->prepare("SELECT eid FROM event WHERE eid = ?"))){
echo "Prepare failed: (" . $mysqli->errno . ")" . $mysqli->error;
}
if(!$stmt->bind_param('s', $eventid)){
echo "Bind failed: (" . $stmt->errno . ")" . $stmt->error;
}
/*execute query */
$stmt->execute();
/* Store the result (to get properties) */
$stmt->store_result();
/* Get the number of rows */
$num_of_rows = $stmt->num_rows;
/* Bind the result to variables */
$stmt->bind_result($eventid2 );
while ($stmt->fetch()) {}
if ($stmt) {
if ($c_name2 == $clubname && $eventid == $eventid2) {
$query1 = 'INSERT INTO sponsored_by (`clubid`, `eid`) VALUES (?,?)';
if(!($stmt = $mysqli->prepare("INSERT INTO sponsored_by (`clubid`, `eid`) VALUES (?,?)"))){
echo "Prepare failed: (" . $mysqli->errno . ")" . $mysqli->error;
}
if(!$stmt->bind_param('ss', $clubname, $eventid)){
echo "Bind failed: (" . $stmt->errno . ")" . $stmt->error;
}
if(!$stmt->execute()){
echo "Execute failed: (" . $stmt->errno .")" . $stmt->error;
}
echo "sponsor added!";
}
else {
echo "Club/Event doesn't exist!";
}
}
else {
$errorMessage = "Error ";
}
/* free results */
$stmt->free_result();
/* close statement */
$stmt->close();
}
?>
<html>
<head>
<title>Add a co-sponsor for an event</title>
<link rel="stylesheet" type="text/css" href="font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="skel.css">
</head>
<body>
<FORM NAME ="form1" METHOD ="POST" ACTION ="cosponsorpage.php">
Club Name: <INPUT TYPE = 'TEXT' Name ='clubname' value="<?PHP print "";?>" maxlength="20">
Event Name: <INPUT TYPE = 'TEXT' Name ='eventname' value="<?PHP print "";?>" maxlength="20">
<P align = center>
<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Add club">
</P>
<a href="logout.php">logout</a> <br>
</body>
</html>