Example #1
0
function process_form()
{
    echo '<div class="table">';
    $item = new Item(MT_TABLE);
    //Strips html
    $slabel = strip_tags($_POST['label']);
    $slink = strip_tags($_POST['link']);
    if (!empty($_POST['_id'])) {
        $query = "UPDATE " . $item->table . " \r\n\t\t\t\t\tSET label = '{$slabel}',\r\n\t\t\t\t\tlink_url = '{$slink}'\r\n\t\t\t\t\tWHERE id = '" . $_POST['_id'] . "';";
    } else {
        $query = "INSERT INTO " . $item->table . "(label, link_url) \r\n\t\t\t\t  VALUES ('{$slabel}','{$slink}');";
    }
    $result = mysql_query($query) or die(mysql_error());
    //retrieve the last inserted id
    $id = mysql_insert_id();
    //make it the value of order from the same table
    $item->order($id);
    echo '<p>Item correctly handled</p>';
    echo '<p>You are being automatically redirected.</p>';
    header('refresh: 1;url=index.php');
}