Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1. #1
    Join Date
    Apr 2006
    Location
    England
    Posts
    1,159
    Tokens
    0

    Latest Awards:

    Default [PHP] How to make a DJ Says

    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:

    PHP Code:
    CREATE TABLE `message` (
      `
    idint(12NOT NULL auto_increment,
      `
    messagevarchar(250NOT NULL default '',
      `
    ipvarchar(250NOT 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 Code:
    <?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 Code:
    <?php
    include('dbconnect.php');
    This is including the code which allows the inputs your going to make to submit values to the database.

    PHP Code:
    $_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.

    PHP Code:
    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.

    PHP Code:
    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:

    PHP Code:
    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.

    PHP Code:
    ?> 
    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.
    Last edited by Mr.OSH; 15-06-2007 at 04:11 PM.
    REMOVED

    Edited by jesus (Forum Super Moderator): Please do not have text in your signature which is over size 4.

  2. #2
    Join Date
    Aug 2004
    Location
    bristol
    Posts
    3,799
    Tokens
    0

    Latest Awards:

    Default

    Either I haven't read it all, or there isn't actually anything showing the message.

  3. #3
    Join Date
    Apr 2006
    Location
    England
    Posts
    1,159
    Tokens
    0

    Latest Awards:

    Default How to actually show the Message

    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 Code:
    <?php
    include('dbconnect.php');
    Add this to the TOP, its connecting to the database for you.

    PHP Code:
    $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 Code:
    <html>
    <body>
    <font size="4">DJ Says</font><br>
    Lets style the page a bit. Add this after the end of your PHP.

    PHP Code:
    <?php echo("$message[message]"); ?>
    This needs to go next. This is what actually shows the message for you.

    HTML Code:
    </body>
    </html>
    Finally we finish of the page.
    REMOVED

    Edited by jesus (Forum Super Moderator): Please do not have text in your signature which is over size 4.

  4. #4
    Join Date
    May 2006
    Posts
    44
    Tokens
    0

    Default

    Good tutorial
    Thanks!
    Last edited by aspeas; 13-08-2006 at 08:48 PM.

  5. #5
    Join Date
    May 2006
    Location
    Manchester
    Posts
    3,216
    Tokens
    475

    Latest Awards:

    Default

    great tutorial, where should i get a database? + rep

  6. #6
    Join Date
    Feb 2006
    Location
    Newcastle
    Posts
    397
    Tokens
    0

    Default

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

  7. #7
    Join Date
    Dec 2005
    Location
    Australia
    Posts
    550
    Tokens
    0

    Default

    Great tutorial +rep.

  8. #8
    Join Date
    May 2006
    Location
    New Zealand
    Posts
    4,452
    Tokens
    0

    Latest Awards:

    Default

    thank you very much!!!!!!!!!!!!!!!!!!!!!
    New Zealand Web/Tech News

  9. #9
    Join Date
    Sep 2005
    Location
    Ipswich (Suffolk)
    Posts
    386
    Tokens
    0

    Default

    Good tutorial weldone +rep.

  10. #10
    Join Date
    Apr 2006
    Location
    England
    Posts
    1,159
    Tokens
    0

    Latest Awards:

    Default

    Thank You

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •