• הרשמה
    • התחברות
    • חיפוש
    • דף הבית
    • אינדקס קישורים
    • פוסטים אחרונים
    • קבלת התראות מהדפדפן
    • משתמשים
    • חיפוש בהגדרות המתקדמות
    • חיפוש גוגל בפורום
    • ניהול המערכת
    • ניהול המערכת - שרת private

    שלוחת API שמשום מה מריץ את הקוד פעמיים.

    עזרה הדדית למשתמשים מתקדמים
    2
    3
    137
    טוען פוסטים נוספים
    • מהישן לחדש
    • מהחדש לישן
    • הכי הרבה הצבעות
    תגובה
    • הגיבו כנושא
    התחברו בכדי לפרסם תגובה
    נושא זה נמחק. רק משתמשים עם הרשאות מתאימות יוכלו לצפות בו.
    • ל
      לעיתים נדירות נערך לאחרונה על ידי

      עשיתי קוד להזנת מונה חשמל וחישוב לדאטה בייס;

      <?php
      
      // Sanitize and validate input
      $ApiPhone = filter_input(INPUT_GET, 'ApiPhone', FILTER_SANITIZE_STRING);
      if (!$ApiPhone) {
           die("Invalid input");
      }
      $new_counter = filter_input(INPUT_GET, 'a', FILTER_VALIDATE_INT);
      if (!$new_counter) {
           die("Invalid input");
      }
      
      // Connect to the database
      $db = new mysqli('localhost', '?', '?!', '?');
      
      // Check for errors
      if ($db->connect_error) {
           die("Connection failed: " . $db->connect_error);
      }
      //the table name
      $table = 'Electricity_meter';
      
      // Prepare and execute the SQL query using a prepared statement
      $sql = "SELECT `sum_counter`, `prev_data` FROM `$table` WHERE `ApiPhone` = ? ORDER BY `prev_data` DESC LIMIT 1";
      $stmt = $db->prepare($sql);
      if (!$stmt) {
           die("Error preparing query: " . $db->error);
      }
      $stmt->bind_param("s", $ApiPhone); // bind the ApiPhone variable to the prepared statement
      $stmt->execute();
      $result = $stmt->get_result();
      
      // Check for errors
      if (!$result) {
           die("Error executing query: " . $db->error);
      }
      
      // Fetch the results
      $row = $result->fetch_assoc();
      if (!$row) {
           die("No results found");
      }
      
      // Perform the calculation
      $result1 = 0;
      if ($new_counter >= $row['sum_counter']) {
           $result1 = ($new_counter - $row['sum_counter']) * 0.6155;
      }
      if ($result1 < 0) {
           $result1 = 0;
      }
      
      // Calculate the number of days between the two dates
      $prev_date = strtotime($row['prev_data']);
      if (!$prev_date) {
           die("Invalid date format");
      }
      $today = strtotime(date('Y-m-d'));
      if (!$today) {
           die("Invalid date format");
      }
      $num_days = floor(($today - $prev_date) / 86400);
      
      // Calculate the result
      $result2 = $num_days * 3.6;
      $result3 = round($result1 + $result2, 2);
      
      // Insert the new data into the table
      $insert_sql = "INSERT INTO `$table` (`sum_counter`, `prev_data`, `sum_payment`, `ApiPhone` ) VALUES ('$new_counter', NOW(), '$result3', '$ApiPhone')";
      $insert_result = $db->query($insert_sql);
      if (!$insert_result) {
           die("Error inserting data: " . $db->error);
      }
      
      // Close the database connection
      $stmt->close();
      $db->close();
      
      // Print the result
      echo "id_list_message=t-סך הכל שעליך לשלם.n-" . str_replace(".", ".t-נקודה.d-", $result3);
      ?>
      
      

      אולם כאשר אני מפעיל את הקוד בשלוחת API, משום מה השרת מקבל פעמיים את ההפעלה, ומוזן לDB פעמיים נתונים (מה שמבלבל את הנתונים לפעם הבאה).

      מישהו מכיר או למאןדהו פתרונים?

      צ תגובה 1 תגובה אחרונה תגובה ציטוט 1
      • צ
        צדיק תמים מומחה @לעיתים נדירות נערך לאחרונה על ידי

        @לעיתים-נדירות מסתמא זה בגלל השליחה הנוספת בניתוק השיחה. תבדוק אם הפרמטר hangup קיים
        https://f2.freeivr.co.il/topic/56/מודול-api-תקשור-עם-מחשבים-וממשקי-נתונים-חיצוניים/2#:~:text=ולהסתיים ללא סלש.-,שליחה בניתוק שיחה,-לאחר שהמשתמש ניתק

        ל תגובה 1 תגובה אחרונה תגובה ציטוט 3
        • ל
          לעיתים נדירות @צדיק תמים נערך לאחרונה על ידי

          @צדיק-תמים
          נכון מאוד

          הסתדר!

          תגובה 1 תגובה אחרונה תגובה ציטוט 1
          • פוסט ראשון
            פוסט אחרון