A Simple PHP Script (MySQL, Too) To Track Radio Station Song Requests, Part 4

In the last post, I discussed the beginnings of the administrative backend for a Web-based radio station request system written in PHP with MySQL.

To wrap the project up, we just need two more pages: One that will list off all the DJs that are in the system now, and one that will delete a DJ record. (Actually, we need to replicate this for the admins of the system, too. However, we’re going to be lazy and just discuss the DJ section, since the admin records are fundamentally the same thing.)

Feature photo by , in the public domain.
Feature photo by TechLine on Pixabay, in the public domain.

Task 1: Display The Current DJ List (dj_list.php)

Other than checking for the presence of the login session variable, there’s nothing to this script: Just get your records and put them out in a table.

<?php
session_start();
if(!isset($_SESSION['login']) || $_SESSION['login'] == "") {
	header('Location: index.php');
}
require_once("../conn.inc.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DJ List</title>
</head>
<body>
<h1>DJ List</h1>
<?php
	$sql = "SELECT * FROM djlist ORDER BY dj_id DESC";
	$rs = mysql_query($sql) or die('Cannot get DJ records');
	if(mysql_num_rows($rs) == 0) {
		echo "<p>There are no DJs.</p>n";
	}
	else {
		echo "<table>n";
		echo "t<tr>n";
		echo "tt<th>Edit</th><th>Public Name</th><th>Delete</th>n";
		echo "t</tr>n";
		while($row = mysql_fetch_array($rs)) {
			echo "t<tr>n";
			echo "tt<td><a href="dj_edit.php?id=$row[dj_id]">Edit</a></td><td>$row[dj_public_name]</td><td><a href="dj_delete.php?id=$row[dj_id]">Delete</a></td>n";
			echo "t</tr>n";
		}
		echo "</table>n";
	}
?>
<p><a href="dj_add.php">Add DJ</a> | <a href="menu.php">Menu</a> </p>
<p>&nbsp;</p>
</body>
</html>

Task 2: Delete A DJ Record (dj_delete.php)

This is really easy. All we do is get the DJ ID, delete the record, and kick the user back to the listing.

session_start();
if(!isset($_SESSION['login']) || $_SESSION['login'] == "") {
	header('Location: index.php');
}
require_once("../conn.inc.php");
$id = $_GET['id'];

$rs = mysql_query("DELETE FROM djlist WHERE dj_id = $id") or die('Cannot delete record');
header('Location: dj_list.php');

And that’s pretty much it (again, after we convert the DJ management files to work with the admins). All that’s left is to install it; and that’s as simple as uploading the files to your Web server and running the SQL scripts through your MySQL database.

Github repo for this project: https://github.com/dougvdotcom/radio-requests/

11 Comments

    1. @Michael: You’ve either added a closing PHP tag prematurely, failed to properly escape a double-quoted sequence, or otherwise miscopied the code. I can help you with your specific implementation in exchange for a Wish List purchase, as described under the link above, “Need More Help Or Want To Say Thanks?”

  1. This script is awesome! But there are multiple errors when using it on php5.3+. It shows errors like this:

    Deprecated: mysql_escape_string(): This function is deprecated; use mysql_real_escape_string() instead. in /{snipped path}/index.php on line 35

    The script still works but I don’t know how to solve these errors and if it will be a big problem in the future.

    I need to run php5.3 or above for my radio player :(.
    Otherwise it wouldn’t be a problem haha.

    1. @jordy: The message means what is says.

      * Open the PHP file in a text editor. I recommend Notepad++ for PC or BBEdit / TextWrangler for Mac.
      * Scroll down to line 35 of the script.
      * Change the function that is named mysql_escape_string to be mysql_real_escape_string.

      This script is 10 years old. So yes, it uses deprecated functions, even for PHP 5.3, which itself is old (as in, you shouldn’t be running PHP 5.3, you should upgrade it).

      If you run a 10-year-old PHP tutorial you found on the Internet as it is, you’re asking for trouble. So yes, you need to fix this script. If you’d like me to do that for you, I am happy to do so, for pay. Email me directly for details.

  2. im getting an error
    Fatal error: Uncaught Error: Call to undefined function mysql_pconnect() in C:\Program Files\Ampps\www\songreq.net\req2\conn.inc.php:26 Stack trace: #0 C:\Program Files\Ampps\www\songreq.net\req2\index.php(2): require_once() #1 {main} thrown in C:\Program Files\Ampps\www\songreq.net\req2\conn.inc.php on line 26

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Check out the Commenting Guidelines before commenting, please!
  • Want to share code? Please put it into a GitHub Gist, CodePen or pastebin and link to that in your comment.
  • Just have a line or two of markup? Wrap them in an appropriate SyntaxHighlighter Evolved shortcode for your programming language, please!