php require_once config php db mysql_connect SERVER_NAME DB_USER DB_PA

  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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
@require_once('config.php');
$db = mysql_connect ( SERVER_NAME, DB_USER, DB_PASSWORD ) or die (mysql_error());
mysql_select_db ( DB_NAME, $db ) or die(mysql_error());
if(isset($_GET['ds']))
{
mysql_query('delete from students where `id` = '.$_GET['ds']);
mysql_query('delete from marks where id_st not in (select `id` from students)');
}
if(isset($_REQUEST['new_button_st']))
mysql_query('insert into students (`name`) values (\''.$_POST['new_sName'].'\')') or die(mysql_error());
elseif(isset($_REQUEST['update_button_st']))
mysql_query('update students set `name`=\''.$_POST['sName'].'\' where `id`='.$_POST['sId']) or die(mysql_error());
if(isset($_GET['dl']))
{
mysql_query('delete from lessons where `id` = '.$_GET['dl']);
mysql_query('delete from marks where id_ls not in (select `id` from lessons)');
}
if(isset($_REQUEST['new_button_ls']))
mysql_query('insert into lessons (`name`) values (\''.$_POST['new_lName'].'\')') or die(mysql_error());
elseif(isset($_REQUEST['update_button_ls']))
mysql_query('update lessons set `name`=\''.$_POST['lName'].'\' where `id`='.$_POST['lId']) or die(mysql_error());
?>
<html>
<head>
<title>sample db php code</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<h1 style="margin-left: 4em;">SMS - Students Management System</h1>
<form method="POST" action="<?php $_SERVER['PHP_SELF'] ?>" name="main_frm">
<table cellpadding="10" border="0">
<tr>
<td align="center"><b>STUDENTS</b></td>
<td width="100px">&nbsp;</td>
<td align="center"><b>LESSONS</b></td>
</tr>
<tr>
<tr>
<!-- new button (students) -->
<td>
<table>
<tr>
<td>Name:</td>
<td>
<input type="text" name="new_sName" />
</td>
<td><input type="submit" name="new_button_st" value="add" /></td>
</tr>
</table>
</td>
<td width="100px">&nbsp;</td>
<!-- new button (lessons) -->
<td>
<table>
<tr>
<td>Name:</td>
<td>
<input type="text" name="new_lName" />
</td>
<td><input type="submit" name="new_button_ls" value="add" /></td>
</tr>
</table>
</td>
</tr>
<!-- students -->
<td>
<table width="100%">
<tr bgcolor="cyan">
<td style="text-transform: uppercase;" align="center">name</td>
<td align="center">Del</td>
</tr>
<?php
$mr = mysql_query("select * from students") or die(mysql_error());
$i = 0;
while ($row = mysql_fetch_row($mr)) {
$color = $i % 2 === 1 ? '#ffffff' : '#dddddd';
printf ('<tr style="background-color:%s;" onmouseover="trOnMouseOver(this);" onmouseout="trOnMouseOut(this);">'.
'<td><a href="%s">%s</a></td>'.
'<td align="center"><a href="%s"><img src="delete.jpg" /></a></td>'.
'</tr>',
$color,
$_SERVER['PHP_SELF'].'?ss='.$row[0],
$row[1],
$_SERVER['PHP_SELF'].'?ds='.$row[0]);
$i++;
}
?>
</table>
</td>
<td width="100px">&nbsp;</td>
<!-- lessons -->
<td>
<table width="100%">
<tr bgcolor="cyan">
<td style="text-transform: uppercase;" align="center">name</td>
<td align="center">Del</td>
</tr>
<?php
$mr = mysql_query("select * from lessons") or die(mysql_error());
while ($row = mysql_fetch_row($mr)) {
$color = $i % 2 === 1 ? '#ffffff' : '#dddddd';
printf ('<tr style="background-color:%s;" onmouseover="trOnMouseOver(this);" onmouseout="trOnMouseOut(this);">'.
'<td style="text-transform: capitalize;"><a href="%s">%s</a></td>'.
'<td align="center"><a href="%s"><img src="delete.jpg" /></a></td>'.
'</tr>',
$color,
$_SERVER['PHP_SELF'].'?sl='.$row[0],
$row[1],
$_SERVER['PHP_SELF'].'?dl='.$row[0]);
$i++;
}
?>
</table>
</td>
</tr>
<tr>
<!-- update button (students)-->
<td>
<table>
<tr>
<td>Name:</td>
<td>
<?php
if(isset($_GET['ss']))
$mr = mysql_query('select `name`, `id` from students where `id` = '.$_GET['ss']) or die(mysql_error());
else
$mr = mysql_query("select `name`, `id` from students where `id` = (select min(`id`) from students)") or die(mysql_error());
while($row = mysql_fetch_row($mr)) {
printf ('<input type="text" name="sName" value="%s" /><input type="hidden" name="sId" value="%s"/>',
$row[0], $row[1]);
}
?>
</td>
<td><input type="submit" name="update_button_st" value="update" /></td>
</tr>
</table>
</td>
<td width="100px">&nbsp;</td>
<!-- update button (lessons)-->
<td>
<table>
<tr>
<td>Name:</td>
<td>
<?php
if(isset($_GET['sl']))
$mr = mysql_query('select `name`, `id` from lessons where `id` = '.$_GET['sl']) or die(mysql_error());
else
$mr = mysql_query("select `name`, `id` from lessons where `id` = (select min(`id`) from lessons)") or die(mysql_error());
while($row = mysql_fetch_row($mr)) {
printf ('<input type="text" name="lName" value="%s" /><input type="hidden" name="lId" value="%s"/>',
$row[0], $row[1]);
}
?>
</td>
<td><input type="submit" name="update_button_ls" value="update" /></td>
</tr>
</table>
</td>
</tr>
</table>
<br /><br />
<a href="marks.php" target="_blank">show marks</a>
</form>
</body>
</html>
<?php
mysql_close($db);
?>