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 TABLE in_out(username varchar(20) not null primary key, status SET('In', 'Out') NOT NULL, location varchar(30), returning varchar(30) );
<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>
<?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" />
{{ mysql.table{query: "SELECT username as 'User Name', status as Status, location as Location, returning as Returning FROM in_out ORDER BY username"} }}
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.
| File | Version | Size | Modified | |
|---|---|---|---|---|
| ||||
| ||||
Copyright © 2011 MindTouch, Inc. Powered by
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
Thanks for this work!!