Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How To Create A Form Similar To This?

    http://www.kingdomslivecodes.com/

    I've always seen these types of sites and I've always wondered how to make one. What I basically mean is a self posting form that people can post codes to every X amount of hours/days/weeks/etc. Can someone help me out with this?

  • #2
    Regular Coder
    Join Date
    Mar 2011
    Posts
    148
    Thanks
    0
    Thanked 20 Times in 20 Posts
    Hi,
    To store and display data added in form, it is needed a server side script language (like PHP) that receives form data, checks the verification code (which is also stored in a session) save data into a file or database, select and display the records.
    That is the ideea, but it is needed to learn /know some php to apply it. Here's a tutorial Using HTML form in PHP.

  • #3
    Regular Coder dan-dan's Avatar
    Join Date
    Aug 2009
    Location
    England
    Posts
    483
    Thanks
    22
    Thanked 79 Times in 78 Posts
    I just had an attempt at it using PHP and MySQL.

    PHP file.
    PHP Code:
    <?php

    $db_hostname 
    'localhost'
    $db_database 'codes'
    $db_username 'danny'
    $db_password 'letmein'

    $db_server mysql_connect($db_hostname$db_username$db_password);

    if (!
    $db_server)
        die(
    "Unable to connect to mysql: " mysql_error());

    mysql_select_db($db_database$db_server)
            or die(
    "Unable to select database: " mysql_error());

    if (isset(
    $_POST['code'])) {
        
    $code strtoupper($_POST['code']);
        if (
    strlen($code) > 7)
            echo 
    "Sorry, too many characters!";
        else if (
    $code == "")
            echo 
    "You didn't enter anything!";
        else {  
            
    $insertResult mysql_query("INSERT INTO codes (code) VALUES ('".$code."')");
            
            if (!
    $insertResult) {
                echo 
    "Sorry, you encountered a problem: " mysql_error();
            }
        }
    }

    $result mysql_query("SELECT * FROM codes");

    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>Add codes</title>
            
            <style type="text/css">
                
                #results {
                    width: 50%;
                    margin-top: 15px;
                    padding: 5px;
                    background: aquamarine;
                }
                
                .container {
                    width: 20%;
                    display: inline-block;
                }
                
                .number {
                    margin-right: 5px;
                    font-weight: 600;
                }
            </style>
        </head>
        
        <body>
            <form method="post" action="">
                <input type="text" size="20" name="code" />
                <input type="submit" value="Add code" />
            </form>
            
            <div id="results">
            <?php
            $rows 
    mysql_num_rows($result);
            for (
    $i 0$i $rows$i++) {
                echo 
    '<div class="container"><span class="number">'.($i 1).'.</span>'mysql_result($result$i'code').'</div>';
            }
            
    ?>
            </div>
        </body>
    </html>
    SQL dump file.
    Code:
    -- phpMyAdmin SQL Dump
    -- version 3.4.5
    -- http://www.phpmyadmin.net
    --
    -- Host: 127.0.0.1
    -- Generation Time: May 20, 2012 at 04:45 PM
    -- Server version: 5.5.16
    -- PHP Version: 5.3.8
    
    SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
    SET time_zone = "+00:00";
    
    
    /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
    /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
    /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
    /*!40101 SET NAMES utf8 */;
    
    --
    -- Database: `codes`
    --
    
    -- --------------------------------------------------------
    
    --
    -- Table structure for table `codes`
    --
    
    CREATE TABLE IF NOT EXISTS `codes` (
      `id` int(3) NOT NULL AUTO_INCREMENT,
      `code` varchar(7) CHARACTER SET utf8 NOT NULL,
      PRIMARY KEY (`id`),
      UNIQUE KEY `code` (`code`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=16 ;
    
    /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
    /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
    /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


  •  

    Posting Permissions

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