Hello
Well this is my first tutorial and hope it hepls out people who need a DJ Says with MySQL Database.
To Start it of,
You will need to have a host that supports PHP and MySQL,
Create MySQL Database.
After that,
Go to your PHPMyAdmin or MySQL Database Editing Area. And copy and paste in.
Code:CREATE TABLE `djsays` ( `ID` int(4) NOT NULL auto_increment, `user` varchar(20) NOT NULL default '', `message` varchar(100) NOT NULL default '', `active` char(1) NOT NULL default '', PRIMARY KEY (`ID`) ) ENGINE=MyISAM AUTO_INCREMENT=0 ;
Once you have done that make a file called "config.php" and put in.
PHP Code:<?
session_start();
// DB Vars
$dbUser = 'admin'; # DB USER
$dbPass = 'admin'; # DB PASS
$dbName = 'admin'; # DB NAME
// Connect
mysql_connect ("localhost", "$dbUser", "$dbPass");
mysql_select_db ("$dbName");
// Sessions
$Username = $_SESSION['user'];
$Password = $_SESSION['pass'];
?>
Where it has
PHP Code:$dbUser = 'admin'; # DB USER
$dbPass = 'admin'; # DB PASS
$dbName = 'admin'; # DB NAME
Change "admin" to your own database
after that make a file called "djsays.php"
PHP Code:<?
require('config.php');
// Get DJ Message
$getQuery = mysql_query("SELECT * FROM djsays WHERE active='Y'");
if(mysql_num_rows($getQuery) =="0"){
$message ="There is no current DJ Message, Sorry.";
}else{
$getData = mysql_fetch_array($getQuery);
$message = "$getData[message]";
}
Echo"$message";
?>
Once you have saved them we will come onto the MySQL bit whats not hard to do and will only take about 2Mins to do.
Now create a folder and call it "secure"
Inside that folder make a file called "config.php"
and paste in,
PHP Code:<?
session_start();
// DB Vars
$dbUser = 'admin'; # DB USER
$dbPass = 'admin'; # DB PASS
$dbName = 'admin'; # DB NAME
// Connect
mysql_connect ("localhost", "$dbUser", "$dbPass");
mysql_select_db ("$dbName");
// Sessions
$Username = $_SESSION['user'];
$Password = $_SESSION['pass'];
?>
Now we have done that theres one more file to make.
This file call it "index.php" and save it in secure.
PHP Code:<?
require('config.php');
switch($_GET['act']){
default:
Echo"<center><b>DJ-Says</b></center>
To clear your DJ messages, click
<a href='index.php?act=remove'>here</a>.
<hr width='100%' height='1' color='#000000' shade='no'>
<form method='post' action='index.php?act=change'>";
// Saved Messages
$savedQuery = mysql_query("SELECT * FROM djsays WHERE user ='$userData[user]' ORDER BY ID ASC");
while($savedData = mysql_fetch_array($savedQuery)){
Echo"<input type='radio' name='ID' value='$savedData[ID]'> $savedData[message]<br>";
}
Echo"
<input type='submit' value='Update'>
</form>
<hr width='100%' height='1' color='#000000' shade='no'>
<form method='post' action='index.php?act=create'>
<font color='red'>WARNING:</font> You cannot use HTML inside DJ Messages.<br>
Message (Max 100 Characters): <input type='text' name='message' size='20' maxlength='100'><br>
<input type='submit' value='Submit'>";
break;
case"change":
$ID = $_POST['ID'];
// Valid
$validQuery = mysql_query("SELECT * FROM djsays WHERE ID ='$ID' AND user ='$userData[user]'");
if(mysql_num_rows($validQuery) =="0"){
Echo"<b>Error:</b> Either this Message has been deleted, or is not own by
yourself, please press the back button on your browser and try again.";
exit;
}
mysql_query("UPDATE djsays SET active='N'");
mysql_query("UPDATE djsays SET active='Y' WHERE ID ='$ID'");
Echo"<b>Message Updated Successfully</b><br>
- <a href='index.php'>Back</a>";
break;
case"create":
$message = $_POST['message'];
// Empty
if(empty($message)){
Echo"<b>Error:</b> The message you entered was empty. If you wish to
remove your DJ message, please click
<a href='index.php?act=remove'>here</a>.";
exit;
}
// Security
$message = str_replace("\"","'",$message);
$message = str_replace("<","[",$message);
$message = str_replace(">","]",$message);
$message = str_replace(" ","<br>",$message);
// Add
mysql_query("INSERT INTO djsays (user,message,active) VALUES ('$userData[user]','$message','N')");
Echo"<b>DJ Says Message Added Successfully</b><br>
<u>Note:</u> This message is not active, you must go backwards to activate it.<br>
- <a href='index.php'>Back</a>";
break;
case"remove":
mysql_query("UPDATE djsays SET active='N' WHERE user='$userData[user]'");
Echo"<b>DJ Messages Deactivated.</b><br>
- <a href='javascript:history.go(-2)'>Back</a>";
break;
}
?>
Now i have showed you how to make a DJ Says with MySQL, i dont mind what you do with it and i have put NO copyright stuff on it all i want you not to do is sell it and make profit for something you didnt create.
Hope you like it!
Thanks
Adam





Reply With Quote


