Hello
So i have a php file which receives two variables from another file with jquery ajax with POST method. If i echo these two variables i find out that they are empty.I verify this by using an echo if it is empty BUT if i insert them to my database with an insert query i find out that they have a value . Am i getting crazy? I tried many methods to extract the value from the $_POST but i failed. Note that the jquery ajax which sends the two variables works as intended because my database has the correct values inserted.
if you want the rest of the code or something else please ask me ,work with me because this problem troubles me much
This is where i call it.
$.ajax({
type:"POST",
url:"chat.php",
data: { user1:'<?php echo $uid; ?>', user2:profileId[k] }
});
This is chat.php
<?php
ob_start();
require_once 'online-users.php';
session_start();
include 'dbconnect.php';
$user1 = !empty( $_POST['user1'] ) ? $_POST['user1'] : false;
$user2 = !empty( $_POST['user2'] ) ? $_POST['user2'] : false;
if (empty($user1)) {
echo "yes";
}
$sql = "SELECT chatLog FROM chat WHERE firstId = '".$user1."' AND secondId = '".$user2."' ";
$result = mysqli_query($conn, $sql);
$count = mysqli_num_rows($result);
if($count == "0"){
$sql1 = "INSERT INTO chat (firstId, secondId) VALUES ('".$user1."', '".$user2."')";
$result1 = mysqli_query($conn, $sql1);
}else{
while ($row = mysqli_fetch_assoc($result)) {
$log = $row['chatLog'];
}
}
$uid = $session;
if( !isset($_SESSION['user']) ) {
header("Location: index.php");
exit;
}
?>
And this is proof that the numbers are being saved in the database and that they have value indeed.
