-3

how can i get userid from my mysql database and implement it in the code. I can't use regular PHP variable.

$device_id = mysqli_query($conn,"SELECT notification_id FROM app WHERE customer_id='$form_customer_id' AND status='ACTIVE'");
if(mysqli_num_rows($device_id) >= 1) 
{ 
while($row = mysqli_fetch_array($device_id))
{
$onesignal_id=$row['notification_id'];
}}

and here is a code

    $content      = array(
        "en" => 'TEST PUSH MES'
    );
    $hashes_array = array();
    array_push($hashes_array, array(
        "id" => "like-button",
        "text" => "Like",
        "icon" => "xxx",
        "url" => "xxx"
    ));
    array_push($hashes_array, array(
        "id" => "like-button-2",
        "text" => "xxx",
        "icon" => "xxx",
        "url" => "xxx"
    ));
    $fields = array(
        'app_id' => "xxx",
        'include_player_ids' => array(
        'HERE I HAVE PROBLEM. I need to get the user id at this point from my MYSQL DATABASE'
),
        'data' => array(
            "foo" => "bar"
        ),
        'contents' => $content,
        'web_buttons' => $hashes_array
    );
    
    $fields = json_encode($fields);
    print("\nJSON sent:\n");
    print($fields);
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json; charset=utf-8',
        'Authorization: Basic xxxxxxx'
    ));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    
    $response = curl_exec($ch);
    curl_close($ch);
    
    return $response;
}

$response = sendMessage();
$return["allresponses"] = $response;
$return = json_encode($return);

$data = json_decode($response, true);
print_r($data);
$id = $data['id'];
print_r($id);

print("\n\nJSON received:\n");
print($return);
print("\n");

I need to get the user ID from the database and put it in the script. Unfortunately, I am learning and I don't really know how to interfere with the code. I thought I could put a variable there, unfortunately it doesn't work

Thx for help! :)

pham_r
  • 1
  • 1
    **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/32391315) – Dharman May 28 '22 at 21:13
  • 1
    _" it doesn't work"_ - this is not a problem description. **What** doesn't work? Do you get an error message? Do you get the wrong data? No data at all? – Tangentially Perpendicular May 28 '22 at 21:26
  • Normally PHP users connect to the database and talk directly. What's with CURL?? – Rick James May 28 '22 at 22:27

0 Answers0