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 16
  1. #1
    Join Date
    Aug 2004
    Location
    Over there. ^_^
    Posts
    1,100
    Tokens
    0

    Latest Awards:

    Default [PHP] Tutorial: Making a basic Download CMS (uses mysql)

    Hey,
    I put these codes together using various other php scripts using mysql
    This tutorial will explain how to make a basic download cms, this will allow you to view the downloads (obviously), add downloads with a form, have a click counter to show how many times the file was downloaded, anyway...

    First of all you will need a file to connect to your mysql DB
    PHP Code:
    <?php
    $username 
    "";//your username
    $password "";//your password
    $host "localhost";//your mySQL server
    $database "";//The name of the database your table is in

    mysql_connect($host,$username,$password) or die("Error connecting to Database!<br>" mysql_error());//connect, but if there is a problem, display an error message telling why there is a problem
    mysql_select_db($database) or die("Cannot select database!<br>" mysql_error());//Choose the database from your mySQL server, but if there is a problem, display an error telling why
    ?>
    save that as dbconnect.php
    next you will need to install the tables to your DB create a file called install.php and add this code:
    PHP Code:
    <?php
    include ('dbconnect.php');
    //create the table, customize it if you want
    $query 'CREATE TABLE downloads(
    id INT NOT NULL AUTO_INCREMENT,
    PRIMARY KEY(id),
    title VARCHAR(100) NOT NULL,
    avatar VARCHAR(100) NOT NULL,
    url VARCHAR(100) NOT NULL,
    categorie VARCHAR(100) NOT NULL,
    descrip VARCHAR(100) NOT NULL,
    date varchar(50) NOT NULL default "0000-00-00",
    author VARCHAR(100) NOT NULL,
    added VARCHAR(100) NOT NULL,
    total VARCHAR(100) NOT NULL)'
    ;
    $result mysql_query($query);
    echo 
    "Table Created!";
    ?>
    this will create the required tables needed for the downloads system.
    Creating the click counter,
    The click counter will record how many times the download has been clicked, this will record this in the mysql table 'total' and display it with the download description heres the code:
    PHP Code:
    <?php
    include ('dbconnect.php');

    $id $_GET['id']; //Gets the id from the browser, ie, count.php?id=2
    if (!is_numeric($id)) //if the id is NOT a number exits the script
    {
    exit;
    }
    mysql_query ("UPDATE downloads SET total = total + 1 WHERE id = '$id'"); //makes a database query and updates the field named total with the previous total +1(for the click)
    $result mysql_query("SELECT * FROM downloads WHERE id = '$id'"); //makes another query and selects all from the table affiliates where field id equals the variable id(which we defined as the GET function)
    $row mysql_fetch_object ($result);
    header("Location: " $row->url); //makes a redirect to the specified URL of the link found in the database.
    ?>
    Now the next thing is diplaying the download create a file called downloads.php and add this code to it:
    PHP Code:
    <?php 
    include ('dbconnect.php');

    $result mysql_query("SELECT * FROM downloads ORDER BY total DESC"); // makes a query to database to table "affiliates" and orders it by total descending
    while ($row mysql_fetch_object($result)) { // while loop While you are connected to the database do this...
    echo "<table width='100%' cellspacing='2' class='downloads' cellpadding='0'>
      <tr> 
        <td width='40' height='40' valign='top'><a href='downloads/count.php?id="
    .$row->id."'><img src='".$row->avatar."' border='0' width='40' height='40'></a></td>
        <td class='description' valign='top'><b><a href='downloads/count.php?id="
    .$row->id."'>".$row->title."</a></b><br>
        Category: "
    .$row->categorie."<br>
        "
    .$row->descrip."<br>
        Author: "
    .$row->author." // Added by: ".$row->added." // Date Added: ".$row->date."<br>
        Downloads: "
    .$row->total."
    </td>
      </tr>
    </table><br>
    "

    }
    ?>
    This will display all of the downloads and the newest download will appear at the top. Now then adding the download using a form, this form will insert the details into your mysql DB, if you get anything wrong you will have to edit it via phpmyadmin or whatever you are using for now, Here is the code to add the downloads:

    PHP Code:
    <?php
    include ('dbconnect.php');

    if(!empty(
    $title)) {//if the title is not empty, than do this function
    $title addslashes($title);
    $avatar addslashes($avatar);
    $url addslashes($url);
    $categorie addslashes($categorie);
    $descrip addslashes($descrip);
    $author addslashes($author);
    $added addslashes($added);
    $total addslashes($total);

    $date date("F j, Y");//set up the date format
    $date2 mktime();

    $sql "INSERT INTO downloads (id, title, avatar, url, categorie, descrip, date, author, added, total) VALUES ('NULL', '$title','$avatar','$url', '$categorie', '$descrip', '$date', '$author', '$added', '$total')";//Insert all of your information into the mynews table in your database
    $query mysql_query($sql) or die("Cannot query the database.<br>" mysql_error());
    echo 
    "Download Added.";
    } else {
    ?>
    <form name='news' method='post' action='index.php?show=adddl'>
    <p>Please fill out all of the following fields:</p>
    <table width='100%' border='0' cellpadding='0' cellspacing='0'>
    <tr>
    <td width='117'>Download Title*:</td>
    <td width='577'>
    <input type='text' name='title' size='50'>
    </td>
    </tr>
    <tr>
    <td width='117'>Avatar (40x40)*:</td>
    <td width='577'>
    <input type='text' name='avatar' size='50'>
    </td>
    </tr>
    <tr>
    <td width='117'>Download URL*:</td>
    <td width='577'>
    <input type='text' name='url' size='50'>
    </td>
    </tr>
    <tr>
    <td width='117'>Categorie*:</td>
    <td width='577'>
      <select name='categorie'>
        <option selected>Choose a Category</option>
        <option>PS Brushes</option>
          <option>Fonts</option>
        <option>Scripts</option>
        <option>Other</option>
    </select>
    </td>
    </tr>
    <tr>
    <td width='117'>Description*:</td>
    <td width='577'>
    <textarea name='descrip' cols='50' rows='20'></textarea>
    </td>
    </tr>
    <tr>
    <td width='117'>Author*:</td>
    <td width='577'>
    <input type='text' name='author' size='50'>
    </td>
    </tr>
    <tr>
    <td width='117'>Added by*:</td>
    <td width='577'>
    <input type='text' name='added' size='50'>
    </td>
    </tr>
    <tr>
    <td width='117'>Total Downloads*:</td>
    <td width='577'>
    <input type='text' name='added' value='0' onFocus='this.blur()' size='50'>
    </td>
    </tr>
    </table>
    <p>
    <input type='submit' name='Submit' value='Submit'>
    </p>
    </form>
    <?php
    }
    ?>
    This code should work, ive just been testing it , any problems PM me

    Coming soon...
    - Edit your downloads
    - Delete Downloads
    - Sort out the categories
    - Password protecting the page

    This concludes my tutorial, this tutorial will be added to my site at www.xenigma.co.uk , and is also stickied in my sub-forum
    Last edited by xEnigmA; 06-08-2005 at 11:05 PM.
    *Image Removed


    Ahemm.. How exactly was my sig innapropriate?
    Goddamit i hate this forum :@
    I RESIGN FROM GRAPHICS DESIGNER :@ :@ :@

  2. #2
    Join Date
    Jun 2005
    Location
    USA
    Posts
    2,047
    Tokens
    0

    Latest Awards:

    Post

    10/10 VERY GOOD :p

  3. #3
    Join Date
    Jun 2005
    Posts
    4,795
    Tokens
    0

    Latest Awards:

    Default

    Hehehe *makes better 1*

  4. #4
    Join Date
    Jul 2004
    Location
    Webby Forums!
    Posts
    1,879
    Tokens
    0

    Latest Awards:

    Default

    +rep well done dude


    Chilimagik.net // Reviews, Band Biographies, News, Pics + Loads More!!
    [Thybag.co.uk - Vive la revolutione]

  5. #5
    Join Date
    Aug 2004
    Location
    Over there. ^_^
    Posts
    1,100
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Tomdarkness2
    Hehehe *makes better 1*
    no chance ¬_¬

    how do you get these things stickied ?
    *Image Removed


    Ahemm.. How exactly was my sig innapropriate?
    Goddamit i hate this forum :@
    I RESIGN FROM GRAPHICS DESIGNER :@ :@ :@

  6. #6
    Join Date
    Mar 2005
    Location
    Dog House
    Posts
    1,000
    Tokens
    0

    Latest Awards:

    Default

    By getting anderman to bug the mods

  7. #7
    Join Date
    Aug 2004
    Location
    Over there. ^_^
    Posts
    1,100
    Tokens
    0

    Latest Awards:

    Default

    rofl! sounds like fun >:~D
    *Image Removed


    Ahemm.. How exactly was my sig innapropriate?
    Goddamit i hate this forum :@
    I RESIGN FROM GRAPHICS DESIGNER :@ :@ :@

  8. #8
    Join Date
    Mar 2005
    Location
    Dog House
    Posts
    1,000
    Tokens
    0

    Latest Awards:

    Default

    It can be Want somthing done ask Anderman! He is soooooo famous with them mods :p

  9. #9
    Join Date
    Aug 2004
    Location
    Over there. ^_^
    Posts
    1,100
    Tokens
    0

    Latest Awards:

    Default

    is there any other way without involving anderman :rolleyes: (rofl)
    *Image Removed


    Ahemm.. How exactly was my sig innapropriate?
    Goddamit i hate this forum :@
    I RESIGN FROM GRAPHICS DESIGNER :@ :@ :@

  10. #10
    Join Date
    Aug 2004
    Location
    Sawley
    Posts
    771
    Tokens
    1,631
    Habbo
    T0X!C-uk

    Latest Awards:

    Default

    Quote Originally Posted by xEnigmA
    how do you get these things stickied ?
    By waiting untill i see it
    STICKIED (Moved to tutorials)

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
  •