I make a form with 2 input, one is text another is hidden that store the value of my variables. Then I write a jquery script with post method to pass the value to another php file which will insert the values to a database, But only the value from text input are inserted, the value from hidden input doesn't work. Here are the form and the jquery script:
<?php
include_once('header.php');
$uid = $_GET['uid'];
echo $uid;
[enter image description here][1]?>
<form>
<input name="usermsg" type="text" id="usermsg" size="63" />
<input type="hidden" name="uid" value="<?php echo $uid; ?>">
<input name="submitmsg" type="submit" id="submitmsg" value="Send" />
</form>
$(document).ready(function () {
$("#submitmsg").click(function () {
var clientmsg = $("#usermsg").val();
var clientid = $("#uid").val();
$.post("includes/postchat.php", {text: clientmsg,uid: clientid});
$("#usermsg").attr("value", "");
return false;
});
And here is the postchat.php file:
if (isset($_SESSION['u_uid'])) {
include('dbh-inc.php');
$text = mysqli_real_escape_string($conn, $_POST['text']);
$uid = $_POST['uid'];
$date_current = date("Y-m-d H:i:s");
$user = $_SESSION['u_uid'];
if ($user = 'one') {
if ($text != '') {
$sql = "INSERT INTO messages (body, user_from, date_sent, user_to) VALUES (
'$text',
'$user',
'$date_current',
'$uid'
)";
mysqli_query($conn, $sql);
}
My table in database after submit:
var clientid = $("#uid").val();