Was this page helpful?

In Out Board

    Table of contents
    No headers

    This combination of html form and php script will push data to a mysql database which can then be displayed on a wiki page through the mysql extension.

    This method may not be best practice, or safe on a public wiki, so use at your own risk.

    • Create the new database
      • SSH into your Deki, and log into mysql: mysql -u 'username -p'password'
      • Create a new database: create database inoutdb
      • Create a table with the columns Username, Status, Location, Returning: 
    CREATE TABLE in_out(username varchar(20) not null primary key, status SET('In', 'Out') NOT NULL, location varchar(30), returning varchar(30) );
    • Set up the HTML form. What I am currently using looks like this:
      • <form method="post" action="posttodb.php">
        <p>
        <b>In/Out Board</b><BR>
        <a href=http://wiki.domain.com/locationofboard target="_parent" style="font-size:10px;">View Board</a><BR>
        Username:<BR>
        <INPUT type="text" name="username"><BR>
        Status:<BR>
        <select name="status">
        <option value="in">In the Office</option>
        <option value="out">Out of the Office</option>
        </select>
        <BR>
        <!-- <INPUT type="text" name="status"><BR> -->
        Location:<BR>
        <INPUT type="text" name="location"><BR>
        Returning:<BR>
        <INPUT type="text" name="returning"><BR>
        <input type="submit" value="Submit">
        </P>
        </form>
      • The form displays like this:
      • inoutform.PNG
    • Set up the PHP form:
      • <?php
        // Define the Variables, which are pulled from the form.html
        $username = $_REQUEST['username'] ;
        $status = $_REQUEST['status'] ;
        $location = $_REQUEST['location'] ;
        $returning = $_REQUEST['returning'] ;
        $submit = $_REQUEST['submit' ] ;
        // Define the connection parameters to connect to the MySQL database
        $conn = mysql_connect("localhost", "root", "password");
        mysql_select_db("inoutdb",$conn);
        // If connection does not work, let the user know
        if (!$conn)
          {
          die('Could not connect: ' . mysql_error());
          }
        // Actual SQL command to insert new data into database. The On DUPLICATE KEY UPDATE command ensures
        // That if the key exists, it will be updated instead of a new one created.
        $sql="INSERT INTO in_out (username, status, location, returning)
        VALUES ('$username', '$status','$location','$returning')
        ON DUPLICATE KEY UPDATE status=VALUES(status), location=VALUES(location), returning=VALUES(returning)";
        // Provides feedback for the user to know their submission was successful
        if (!mysql_query($sql,$conn))
          {
          die('Error: ' . mysql_error());
          }
        echo "Update Successful";mysql_close($con)
        ?>
        <!-- Refreshes the page after 3 seconds, going back to the form. -->
        <meta http-equiv="refresh" content="3;url=http://wiki.swg.ca/config/inout/form.html" />
    • Place the form.html and posttodb.php in /var/www/deki-wiki/config/inout/
    • You can use an Iframe to display the form.html, but I plan on using a custom HTML area on the wiki through the control panel. This has yet to be tested.
    • Set up the MySQL extenstion to point to the new database
    • On the page of your choice, use the following mysql extension command to display the records in the table:
      • {{ mysql.table{query: "SELECT username as 'User Name', status as Status, location as Location, returning as Returning  FROM in_out ORDER BY username"} }}

    • This will display like this:
      •   table.PNG

     

    If you have a Single Sign On system, you can pass the username directly to the php script to avoid user input. In the form, change the username INPUT line to this:

    <INPUT type="hidden" name="username" value="{{user.name }}">

     This will only work if you have the form placed through a template.

    Was this page helpful?
    Tag page

    Files 2

    FileVersionSizeModified 
    Viewing 2 of 2 comments: view all
    Hi! this is cool!
    is there any way to add a command into posttodb.php in order to send a mail after insert the values?
    I tried "mail function" but it didn't send any mail, I think i have to configure my apache or PHP but I dont know how..
    any ideas?
    regards! edited 14:04, 20 Apr 2009
    Posted 13:51, 20 Apr 2009
    On my installation (MT Core VM v9.02.4) the files go in /var/www/dekiwiki/config/inout/ (no hyphen in the 'dekiwiki').
    Thanks for this work!!
    Posted 04:32, 4 Aug 2009
    Viewing 2 of 2 comments: view all
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by