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!


Results 1 to 6 of 6

Thread: Petition

  1. #1
    Oni Guest

    Default Petition

    Whats a code for creating a petition kind of thing where people add there names to it. Im assuming it will be php and i preferably dont want to dl anything. Thanks.

  2. #2
    Join Date
    Jul 2006
    Location
    Athens
    Posts
    842
    Tokens
    0

    Default

    You'd need a mysql database and a few statments.
    to add a name to the list.
    Code:
    <?php
    $con = mysql_connect("localhost","DATABASE USERNAME","DATABASE PASS");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }     mysql_select_db("DATABASE NAME", $con);     mysql_query("INSERT INTO pertition (FirstName, LastName) 
    VALUES ('$firstname', '$lastname')") or die ("Could not insert");
    echo "Thank you, Your name has been added to the pertition";
             echo "<form method='post' action='$PHP_SELF?action=add'>
    
    <table border=\"0\" cellpadding=\"2\" cellspacing=\"5\">
    
    <tr><td><font face=\"Verdana\" size=\"1\"><b>First Name:</b></td><td><font face=\"Verdana\" size=\"1\"><input type=\"text\" name=\"firstname\" size=\"20\"></td></tr>
    
    <tr><td><font face=\"Verdana\" size=\"1\"><b>Last Name:</b></td><td><font face=\"Verdana\" size=\"1\"><input type=\"text\" name=\"lastname\" size=\"20\"></td></tr>
    <tr><td></td><td><input type='submit' name='submit' value='Apply!'></td></tr>
    </form>";
    
    ?>
    To View the pertition
    Code:
    <?php
    // Make a MySQL Connection
    mysql_connect("localhost", "DATABASE USERNAME", "DATABASE PASS") or die(mysql_error());
    mysql_select_db("DATABASE NAME") or die(mysql_error());
    
    // Get all the data from the "example" table
    $result = mysql_query("SELECT * FROM pertition") 
    or die(mysql_error());  
    
    echo "<table border='1'>";
    echo "<tr> <th>First Name</th> <th>Last Name</th> </tr>";
    // keeps getting the next row until there are no more to get
    while($row = mysql_fetch_array( $result )) {
        // Print out the contents of each row into a table
        echo "<tr><td>"; 
        echo $row['firstname'];
        echo "</td><td>"; 
        echo $row['lastname'];
        echo "</td></tr>"; 
    
    } 
    
    echo "</table>";
    ?>


  3. #3
    Oni Guest

    Default

    Thanks! :eusa_danc +rep

  4. #4
    Join Date
    Aug 2004
    Location
    UK
    Posts
    11,283
    Tokens
    2,031

    Latest Awards:

    Default

    o.0 from what i can tell the mysql table structure to go with that is a table name
    'pertition' containing two rows "FirstName" and "LastName" (most likly varchar 255, or possibly text, although that would be a bit of a waste in this instance), although for a vertual petition to hold weight you do also need to record the ip, and a comments also nice.

    Plus unless someone injecting some code in to the mysql is a plan, some validation of the inputs, how ever tiny, probably wouldnt go amiss "/

  5. #5
    Oni Guest

    Default

    grrrr it isnt working

  6. #6
    Join Date
    Jul 2006
    Location
    Athens
    Posts
    842
    Tokens
    0

    Default

    Try
    Add.php
    Code:
    <?php
    $con = mysql_connect("localhost","DATABASE USERNAME","DATABASE PASS");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }     mysql_select_db("DATABASE NAME", $con);     
    if($action == "add") {
    
    $add = mysql_query("INSERT INTO `pertition` ( `firstname`, `lastname`) VALUES ('$firstname', '$lastname')");
    
    echo "Your name has been added to the pertition";
    
    } else {
            
    echo "<form method='post' action='$PHP_SELF?action=add'>
    
    <table border=\"0\" cellpadding=\"2\" cellspacing=\"5\">
    
    <tr><td><font face=\"Verdana\" size=\"1\"><b>First Name:</b></td><td><font face=\"Verdana\" size=\"1\"><input type=\"text\" name=\"firstname\" size=\"20\"></td></tr>
    
    <tr><td><font face=\"Verdana\" size=\"1\"><b>Last Name:</b></td><td><font face=\"Verdana\" size=\"1\"><input type=\"text\" name=\"lastname\" size=\"20\"></td></tr>
    <tr><td></td><td><input type='submit' name='submit' value='Apply!'></td></tr>
    </form>";
    }
    
    ?>

    View.php

    Code:
    <?php
    // Make a MySQL Connection
    mysql_connect("localhost", "DATABASE USERNAME, "DATABASE PASS") or die(mysql_error());
    mysql_select_db("DATABASE NAME) or die(mysql_error());
    
    // Get all the data from the "example" table
    $result = mysql_query("SELECT * FROM pertition") 
    or die(mysql_error());  
    
    echo "<table border='1'>";
    echo "<tr> <th>First Name</th> <th>Last Name</th> </tr>";
    // keeps getting the next row until there are no more to get
    while($row = mysql_fetch_array( $result )) {
        // Print out the contents of each row into a table
        echo "<tr><td>"; 
        echo $row['firstname'];
        echo "</td><td>"; 
        echo $row['lastname'];
        echo "</td></tr>"; 
    
    } 
    
    echo "</table>";
    ?>
    MySQL
    Code:
    -- 
    -- Table structure for table `pertition`
    -- 
    
    CREATE TABLE `pertition` (
      `id` int(11) NOT NULL auto_increment,
      `firstname` varchar(50) NOT NULL default '',
      `lastname` varchar(50) NOT NULL default '',
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
    
    -- 
    -- Dumping data for table `pertition`
    --


Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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