I've made a form and would like the data inserted into my database to attache to the user, who's logged in at my website. I've used this form:
<form action="/index.php?option=com_content&view=article&id=41" method="post">
<input type="hidden" name="username" id="username" value="username">
<input type="radio" name="k1" id="k1" value="1">1<input type="radio" name="k1" value="X">X<input type="radio" name="k1" value="2">2<br />
<input type="text" name="k1r" id="k1r">
<div>
<p style="float:left; width:14%; margin-right:2%; background:#eee; color:black; border:1px solid #ccc; padding:10px"><input type="submit" value="Add Records"></p>
</div>
</form>
Ant the 'action' would get this code:
// Check connection
if($mysqli === false){
die("ERROR: Could not connect. " . $mysqli->connect_error);
}
// Escape user inputs for security
$username = $mysqli->real_escape_string($_SESSION['username']);
$k1 = $mysqli->real_escape_string($_POST['k1']);
$k1r = $mysqli->real_escape_string($_POST['k1r']);
// attempt insert query execution
$sql = "INSERT INTO kampbs(username, k1, k1r) VALUES('$user', '$k1', '$k1r')";
if($mysqli->query($sql) === true){
echo "Records inserted successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . $mysqli->error;
}
// Close connection
$mysqli->close();
?>
The form-data is inserted as it should, but in the 'Username' field in the database it says 'JUser'. What should I do to get the Logged-in username (should've been the username 'DJ').