i have spent a day now but i am not able to solve the following problem. I have this code to access my database and i want to get some values. The weird thing is, that the same code works for the same php file on the same server in the same directory. I wanted to create a new php file with a different sql selection, but this one always returns null instead of a json array.
Any helpful advice would be great! I am running a wordpress site, maybe thats an important information.
<?php
if( isset( $_POST[user_id] ) )
{
$user_id = $_POST[user_id];
$servername = "****";
$username = "****";
$password = "****";
$dbname = "****";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//echo "Connected successfully";
//echo $user_id;
$sql = "SELECT *
FROM felderkonfig
WHERE felderkonfig_user_id = '$user_id' ";
$result = mysqli_query($conn, $sql); //sql abfrage in array speichern
$myArray = array();
$myArray =mysqli_fetch_assoc($result); //umwandeln in assoziatives array
echo json_encode($myArray); //echo als json array
$conn->close();
exit();
}else{
echo "Fehler bei if isset";
}
?>