PDA

View Full Version : Like OMG My Fist Tutorial [DJ Says]



ADAM:
31-01-2006, 08:13 PM
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.

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.

<?
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

$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"

<?
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,

<?
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.


<?
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

Coding4Newbs
31-01-2006, 08:16 PM
Really good tutorial well done

Aao
31-01-2006, 08:20 PM
Great Tut! 10/10 On effort aswell! Great tut! THANKS!

ADAM:
31-01-2006, 08:24 PM
Thanks Aao
And Sygon since you said its a really tutorial good im going to more, once i think of some thing different to do :)

- Adam
Plus rep to both if i can :D

Dan Williamson
31-01-2006, 08:26 PM
Hey,

Awesome tutorial dude, hopefully this will stop posting about how to do it. I reviewed your code *yawns* and I couldn't see anything that was critically wrong with it.

Well done dude, + Rep.

- Dan

ADAM:
31-01-2006, 08:27 PM
Thanks mate :) Plus rep to you if i can :D

- Adam

Edit: You must spread some Reputation around before giving it to Raremandan again

Dan Williamson
31-01-2006, 08:35 PM
Hey,

Rofl it don't matter i'm not here for green bars :)

- Dan

ADAM:
31-01-2006, 08:37 PM
Ok, thanks for the comment mate :D

Hope to do a second tutorial soon

- Adam
Edit: I also sell PHP scripts aswell, but because these tutorial are going well and helping people. I might do some tutorial on the ones that i am selling :D

Dan Williamson
31-01-2006, 08:40 PM
Hey,

Cool we'll be looking forward to it :)

- Dan

Aao
31-01-2006, 08:41 PM
Great Tut! 10/10 On effort aswell! Great tut! THANKS!

Dan Williamson
31-01-2006, 08:44 PM
Hey,

Has anyone tested this script yet?

- Dan

ADAM:
31-01-2006, 08:45 PM
Lol, you posted the same post twice (Aao)10 mins after your first post. Happy to se you liked it :)
- Adam

Edit: to Raremandan, i will upload it to my host when i have time, so people can use it and test it.

Dan Williamson
31-01-2006, 08:48 PM
Hey,

Cheers it's not that I doubt you but I like seeing the working script :P

- Dan

ADAM:
31-01-2006, 08:53 PM
Ok, looks like my host has closed me :S i was hosted with aj-hosting.net. My site was www.adz-site.be but now it doesnt seem to work :S.

- Adam

Coding4Newbs
01-02-2006, 05:44 AM
talk to me on messenger and ill give you a hosting i got like 1000

Jamie.
01-02-2006, 04:04 PM
Really good tutorial ad :)

ADAM:
01-02-2006, 04:19 PM
Thanks Bondie :)
- Adam

Want to hide these adverts? Register an account for free!