Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1
    Join Date
    Dec 2005
    Location
    England | Brighton
    Posts
    1,378
    Tokens
    0

    Latest Awards:

    Default Like OMG My Fist Tutorial [DJ Says]

    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

  2. #2
    Coding4Newbs Guest

    Default

    Really good tutorial well done

  3. #3
    Join Date
    Nov 2005
    Posts
    138
    Tokens
    0

    Default

    Great Tut! 10/10 On effort aswell! Great tut! THANKS!
    yo..?

  4. #4
    Join Date
    Dec 2005
    Location
    England | Brighton
    Posts
    1,378
    Tokens
    0

    Latest Awards:

    Default

    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

  5. #5
    Join Date
    Jun 2005
    Location
    Manchester
    Posts
    3,187
    Tokens
    0

    Latest Awards:

    Default

    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

  6. #6
    Join Date
    Dec 2005
    Location
    England | Brighton
    Posts
    1,378
    Tokens
    0

    Latest Awards:

    Default

    Thanks mate Plus rep to you if i can

    - Adam

    Edit: You must spread some Reputation around before giving it to Raremandan again
    Last edited by ADAM:; 31-01-2006 at 08:28 PM.

  7. #7
    Join Date
    Jun 2005
    Location
    Manchester
    Posts
    3,187
    Tokens
    0

    Latest Awards:

    Default

    Hey,

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

    - Dan

  8. #8
    Join Date
    Dec 2005
    Location
    England | Brighton
    Posts
    1,378
    Tokens
    0

    Latest Awards:

    Default

    Ok, thanks for the comment mate

    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
    Last edited by ADAM:; 31-01-2006 at 08:39 PM.

  9. #9
    Join Date
    Jun 2005
    Location
    Manchester
    Posts
    3,187
    Tokens
    0

    Latest Awards:

    Default

    Hey,

    Cool we'll be looking forward to it

    - Dan

  10. #10
    Join Date
    Nov 2005
    Posts
    138
    Tokens
    0

    Default

    Great Tut! 10/10 On effort aswell! Great tut! THANKS!
    yo..?

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
  •