This could sound stupid (maybe because it is) but I'm having so much problem in an insert query, this is the thing, I have in my first page a query that inserts into a table, the problem is that in my page2, I have EXACTLY the same query, but in this page doesn't work, the weirdest thing is that I echoed a message in the true statement of the query and it echoes, meaning that the query supposedly is already made, but is not, because when I check into the DB, is not there, and other thing! if I want to update the values, it works!, but not in create, I don't know why, but is bothering me a lot!, if someone could help me i really would appreciated, thanks.
Here is the code:
if($radio==2){
echo $_SESSION["in"];
$sqlb = "SELECT * FROM table WHERE idus='$idus';";
$resb = mysqli_query($con, $sqlb);
$res_b = mysqli_fetch_array($resb);
if( !$res_b) {//if not exist on table, create
$sqly="INSERT INTO table (x,y,z)
VALUES ('$x','$y','$z');";
if ($con->query($sqly) === TRUE) {
$_SESSION["in"]=1;
} else {
echo "Error: " . $sqly . "<br>" . $con->error;
}
}else{ //update if exist on table
$sqly="UPDATE table
SET y='$y',z='$z'
WHERE idus='$idus';";
if ($con->query($sqly) === TRUE) {
} else {
echo "Error: " . $sqly . "<br>" . $con->error;
}
}
header('Location: page2.php');
}
The weird thing of all is that passes through true when doing the query and do nothing, also when pasting the exact same query directly into the DB, it works.