include("config.php");

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Brak połączenia z bazą danych");

### Pobież wiadomość
$result =
mysql_query("select id, wiadomosc from lista where stan=0 order by id asc LIMIT 1");

$row = mysql_fetch_array($result);

### Wyślij wiadomość
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$tURL");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);

$message = $row['wiadomosc'];

curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$tusrid:$tpasswd");

$response = curl_exec($curl_handle);

curl_close($curl_handle);

// pobież stan wiadomości
if (empty($response)) {
echo 'wiadomość nie została wysłana';
} else {
echo 'wiadomość została wysłana';
### aktualizacja stanu bazy danych
$mid = $row['id'];
mysql_query("UPDATE lista SET stan = 1 WHERE id = $mid");
}

mysql_close();
?>