PDA

View Full Version : [PHP] How to make a DJ Says



Halting
22-04-2006, 05:21 PM
I'm not sure if there is also a tutorial for this on the forum, but I'll show you how I do it, and probably the most original way of doing it.

To start of, you will need a database. Once you have made yourself a database, run the following query:



CREATE TABLE `message` (
`id` int(12) NOT NULL auto_increment,
`message` varchar(250) NOT NULL default '',
`ip` varchar(250) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=60 ;


Inside your database, you should now have a table named message, and inside the table there should be three fields. ID, Message and IP.

Your database is now setup, and the message that the DJ submits will now be put into the database you just made. We will learn how to make the page where the DJ submits the message later, but first we need to connect to the database.

Make a page named dbconnect.php
Inside dbconnect.php, insert the following code, editing the obvious.


<?php
$connect = mysql_connect("localhost","DATABASE USERNAME","DATABASE PASSWORD");
mysql_select_db(DATABASE NAME) or die(mysql_error());
?>


Now visit this page you just made. If the page is blank, then the connection was successful. If not then you haven't setup your database name/username/password up right.

Now we need to make it so that your DJs can submit their message as the DJ Says.

Make a page named edit.php
To start of we need to include the database connection. To start of your page with the following code.



<?php
include('dbconnect.php');

This is including the code which allows the inputs your going to make to submit values to the database.



$_POST = array_map('strip_tags',$_POST);
$_POST = array_map('htmlspecialchars',$_POST);
if (!get_magic_quotes_gpc()) { $_POST = array_map('addslashes',$_POST); }

This protects the message from SQL attacks. It will hopefully never come in usefull, but you should add it incase a hacker ever gets into the page. To stop anyone else getting into the page you need to protect it. You will learn how to do this later.



if ($_POST[submit]) {
$message = $_POST[message];
$ip = $_POST[ip];
if($message==NULL) {
echo("You cannot leave your message blank.");
}

The top three lines are telling itself what do submit upon submission. The fourth line tells itself that if the message was left null/blank/empty, then it needs to tell them that their submission was unsuccessful.



else{
$message = htmlspecialchars($message);
$ip = htmlspecialchars($ip);
$query = mysql_query("INSERT INTO message (message, ip) VALUES('$message', '$ip')");
}
echo("Your DJ Message was successfully added and should now appear on the homepage.");
}
else {
echo"
<font size=\"4\">DJ Message/Says</font><br>To create your DJ Message, fill in the TEXT you would like below. HTML, BB Code and PHP have all been protected so you can not use any of those coding characters.<br><br><b>Your IP will be recorded for security reasons.</b><br><br>
<center>
<form method=\"POST\">
<input name=\"ip\" type=\"hidden\" value=\"$_SERVER[REMOTE_ADDR]\">
<textarea name=\"message\" cols=\"55\" rows=\"10\"></textarea><br>
<input type=\"submit\" value=\"Submit\" name=\"submit\">
</form>
</center>
";
}

This is the final part of the page, and the most important part too. The HTML inside the following tags:



echo" HTML here ";

Is what is displayed on the page. All the DJ will see is the text explaining what the DJ Says can be used for and the input to enter their message.



?>

Finally, we end of the page.

If there are any errors please let me know. I haven't tested it and I'm geussing it works fine.

Hope it helps!

Edited by opensourcehost (forum moderator): Thread closed because it was bumped.

nets
22-04-2006, 11:50 PM
Either I haven't read it all, or there isn't actually anything showing the message.

Halting
23-04-2006, 09:12 AM
OK. Well, to show the message its simple. We need to again, connect to the database but this time round we are going to collect information instead of submitting it.



<?php
include('dbconnect.php');

Add this to the TOP, its connecting to the database for you.



$select = mysql_query("SELECT message from message order by id DESC LIMIT 1");
$message = mysql_fetch_array($select)
?>

This is telling itself where to find the information. Once the field/table has been found, it will collect the information your after. In this case, the latest DJ Says message written.



<html>
<body>
<font size="4">DJ Says</font><br>

Lets style the page a bit. Add this after the end of your PHP.



<?php echo("$message[message]"); ?>

This needs to go next. This is what actually shows the message for you.



</body>
</html>

Finally we finish of the page.

aspeas
13-08-2006, 08:48 PM
Good tutorial
Thanks!

Wig44.
14-08-2006, 09:37 AM
great tutorial, where should i get a database? + rep

Liam.
14-08-2006, 10:29 PM
If you have cpanel go to MySQL databases, add your database then go to phpmyadmin and add the query.

Evasion
16-08-2006, 09:50 PM
Great tutorial +rep.

ebay
18-08-2006, 07:49 AM
thank you very much!!!!!!!!!!!!!!!!!!!!!

DJ-Cookeh
21-08-2006, 01:41 PM
Good tutorial weldone +rep.

Halting
21-08-2006, 07:31 PM
Thank You

rnix
26-08-2006, 05:20 PM
im confused plz tell me wht it is as im stupid lmao

Microsoft
02-09-2006, 12:01 PM
im confused plz tell me wht it is as im stupid lmao

Very nice tutorial, and what are you stuck with?

Unused
14-06-2007, 07:59 PM
Well Ive Done Everything The Tutorial Tels Me But I Have One Problem Which Is really Anoying

Access denied for user 'alanalan_db'@'82.197.131.25' to database 'message'

that is what comes up when i go on the dbconnect.php file can anybody help?

ive did everything the tutorial tells me everything i have put is basiclly correct like the password the database name and and the database user soo why cant i connect to the server

Edited by opensourcehost (Forum Moderator): Please don't bump old threads.

Flisker
14-06-2007, 08:02 PM
WOW what a bump...

Edited by opensourcehost (Forum Moderator): Please don't post pointlessly.

chrisgocrazyH
15-06-2007, 10:32 AM
Well Ive Done Everything The Tutorial Tels Me But I Have One Problem Which Is really Anoying


that is what comes up when i go on the dbconnect.php file can anybody help?

ive did everything the tutorial tells me everything i have put is basiclly correct like the password the database name and and the database user soo why cant i connect to the server?

rong mysql details

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