I'm building a simplified referral system.
$(document).ready( function() {
    document.getElementById("getref").onclick = function setref() {
        $.ajax({                                      
            url: 'newref.php', // the script to call to get data
            type: "POST",
            dataType: 'json',  // data format  
            data: {ip:<?php echo $_SERVER['REMOTE_ADDR'] ?>},                        
            // you can insert url arguments here to pass to api.php
            // for example "id=5&parent=6"    
            success: function(data) // on receive of reply
            {
                alert('returned ' + data); //get id
                //--------------------------------------------------------------
                // 3) Update html content
                //--------------------------------------------------------------
                $('#bottom_msg').html("<b>freegoldtrial.com/"+id+"</b>");
                // Set output element html
                // http://api.jquery.com/category/selectors/
            } 
        });
    }
});
Inside newref.php
$ip = $_POST['ip'];
$key = substr(md5(microtime()),rand(0,26),5);
include DB.php
if(! $conn ) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db("database", $conn);
$tbl_name = "refs";
$sql="INSERT INTO refs(ip, id) VALUES ('".$ip."','".$key."')";
if (!mysql_query($sql))
{
    die('Error: ' . mysql_error());
}
mysql_close($con)
How do I return the generated $key variable to the index? As you can see, I'm trying to replace div contents with it. Thanks for all the help :)
 
     
    