Location: PHPKode > projects > PHP File Database > fdat/links.php
<?php
/*
###############################################################################
# links.php                                                                   #
###############################################################################
# FDat (File Database) Beta Version                                          #
# Open-Source Project by Jeffrey Gelens (hide@address.com)                  #
# =========================================================================== #
# Copyright (c) 2001 Jeffrey Gelens - All Rights Reserved                     #
#                                                                             #
# This program is free software; you can redistribute it and/or               #
# modify it under the terms of the GNU General Public License                 #
# as published by the Free Software Foundation; either version 2              #
# of the License, or (at your option) any later version.                      #
###############################################################################
*/
require ('sources/functions.php');
require ('settings.php');

mysql_connect ($database['host'], $database['username'], $database['password']) or die ("Can't connect to database server");
mysql_select_db ($database['name']) or die ("Database doesn't exist, check settings.php");

$check = check($PHP_SELF);

if (!$check) {
  echo "Not logged in or session time is expired!!!";
  exit;
}

if ($send == "addLinks") {
  $link = htmlspecialchars(addslashes($link));
  $description = htmlspecialchars(addslashes($description));
  $sql = "INSERT INTO links VALUES ('$id', '$subject', '$link', '$description')";
  $result = mysql_query($sql);
  echo "<font color='#FF0000'>Link added!</font>";
}

head();
head2();

$sql = "SELECT * FROM links WHERE id_subj = '$link'";
$links = mysql_query($sql);
$sql = "SELECT  * FROM subjects";
$subjects = mysql_query($sql);

while ($row = mysql_fetch_array($subjects)) {

  $short_name = $row["short_name"];
  $sql = "SELECT * FROM links WHERE id_subj = '$link' AND subject = '$short_name'";
  $links = mysql_query($sql);
  $check = mysql_result($links, '');


  if ($check) {
    echo "<i><font color='#0AEA98'>" . $row["name"] . "</font></i><br>";
  }

  $sql = "SELECT * FROM links WHERE id_subj = '$link' AND subject = '$short_name'";
  $links = mysql_query($sql);

  while ($row2 = mysql_fetch_array($links)) {
    echo "<li><a href='" . $row2["link"] . "' target='_blank'>" . $row2["description"] . "</a></li><br>";
  }
  if ($check) {
  echo "<br>";
  }
}
echo "<br>><a href='links.php?action=addLinks'>Add Link</a>";

if ($action == "addLinks") {
?>

<form action="links.php" method="post">

<table>
  <tr>
    <td> Category: </td>
    <td> <select name="id">

<?php
$sql = "SELECT * FROM links_subjects";
$result = mysql_query($sql);

while ($row = mysql_fetch_array($result)) {
  echo "<option value='" . $row["id"] . "'>" . $row["name"] . "</option>";
}
echo "</select></td></tr><tr><td>Subject:</td><td><select name='subject'>";

$sql = "SELECT * FROM subjects";
$result = mysql_query($sql);


while ($row = mysql_fetch_array($result)) {
  echo "<option value='" . $row["short_name"] . "'>" . $row["name"] . "</option>";
}

?>

</select>


    </td>
  </tr>
  <tr>
    <td> URL: </td>
    <td> <input type="text" name="link" value="http://"> </td>
  </tr>
  <tr>
    <td> Description: </td>
    <td> <input type="text" name="description" </td>
  </tr>
</table>

<input type="hidden" name="send" value="addLinks">
<input type="submit" value="Add">
</form>

<?php
}
if ($action == "addLinkSubj") {
?>

<form action="links.php" method="post">
Link Category:
<input type="text" name="linkSubj"><br>
<input type="hidden" name="send" value="addLinkSubj">
<input type="submit" value="Add">
</form>

<?php
}
if ($action == "addSubj") {
?>
<form action="admin.php" method="post">
<table>
  <tr>
    <td>Subject:</td>
    <td> <input type="text" name="name"> </td>
  </tr>
  <tr>
    <td>Short Subject (max. 2 characters):</td>
    <td> <input type="text" name="short_name" maxlength="2"> </td>
  </tr>
</table>

<input type="hidden" name="send" value="addSubj">
<input type="submit" value="Add">
</form>
<?php
}
foot();
?>
Return current item: PHP File Database