Admin Page
Admin page is the main page of our script. It displays the entries from the database and allows users to add entries, edit or delete entries from the database.
The following lines of code simply checks whether the user is authenticated or not. If some one tries to access this page directly, he will be redirected back to the login page. Please note that this code portion will be there is every other page as well – which requires this authentication. Hence I won’t be adding these lines when we discuss about such pages:
1: if (isset($_COOKIE["admin_pass"])){
2: if($_COOKIE["admin_pass"]=="mypassword"){
3:
4: }
5: else {
6: header( "Location: index.php?auth=fail" );
7: }
8: }
9: else {
10: header( "Location: index.php?auth=fail" );
11: }
MySQL portion
This script portion does the SQL querying and fetches the entries from the database:
1: $connection=mysql_connect("localhost","root","");
2:
3: if(!$connection)
4: {
5: die('Could not connect: ' . mysql_error());
6: }
7:
8: mysql_select_db("clientlist", $connection);
9:
10: $clientlist = mysql_query("SELECT * FROM Details");
11:
12: echo "<div style='text-align: center;'><br><big style='color: rgb(102, 0, 0);'><big><big><span style='font-weight: bold;'>Client List</span></big></big></big></div><br>";
13:
14:
15:
16: echo "<div align='center'>";
17:
18: echo "<table border='1'> <tr> <th>Name of Client</th> <th>Website Name</th> <th>Service offered from</th> <th>Due date</th> <th>Amount Paid</th> <th>Email Address</th> <th>Contact No</th> </tr>";
19:
20: while($row = mysql_fetch_array($clientlist))
21: {
22: echo "<tr>";
23: echo "<td> <a href=./edit.php?name=" . $row['Name'] . ">". $row['Name'] ."</a></td>";
24: echo "<td>" . $row['Website'] . "</td>";
25: echo "<td>" . $row['Createdon'] . "</td>";
26: echo "<td>" . $row['Expiry'] . "</td>";
27: echo "<td>" . $row['Amount'] . "</td>";
28: echo "<td>" . $row['Email'] . "</td>";
29: echo "<td>" . $row['Phone'] . "</td>";
30: echo "</tr>";
31: }
32: echo "</table>";
33: echo "</div>";
34:
35: mysql_close($connection);
As you can see the I’m using ‘localhost’ as the host and root as the user (with no password). You can improvise this setting by using a configure file (say config.php) to enter the database access details and import (include) that file in this one.
The PHP script connects to the database and selects the database named ‘clientlist’. Then, it uses wildcard (*) to select all entries from the table ‘Details’. The next line is used to print the headings for each column that we are gonna display.
Using mysql_fetch_array , we are fetching each row entry as an array. Then we create cells (td) for each of these elements in our table. By using row[element_name] we can access each entry in a row. Thus, we can list all the entries as rows and columns. Finally, we close the connection.
Now we can add few buttons to enble logging out, adding etc.
1: <div align="center">
2: <input type="submit" value="Add an Entry" onclick="window.location.href='./add.php'"/>
3:
4: <input type="submit" value="Log Out" onclick="window.location.href='./logout.php'"/>
5: <span
6: style="font-style: italic; color: rgb(0, 51, 0);"><br>
7: Click on the 'Name of Client' to edit or delete the entry!<br>
8: </span>
9:
10: </div>




Join Techblog
Facebook Group
Read
Digg entries
Add techblog to
Google reader
[...] reading here: A Database Management Application in PHP – Tutorial 3 | Tech Blog Share and [...]
wow congrats to the author of this. this is a wonderufl and beautifully written post. i love the way you explain things. ill keep reading the other posts as well.