• דף הבית
    • אינדקס קישורים
    • פוסטים אחרונים
    • משתמשים
    • חיפוש בהגדרות המתקדמות
    • חיפוש גוגל בפורום
    • ניהול המערכת
    • ניהול המערכת - שרת private
    • הרשמה
    • התחברות
    1. דף הבית
    2. לעיתים נדירות
    3. הגבוה ביותר
    ל
    מנותק
    • פרופיל
    • עוקב אחרי 0
    • עוקבים 0
    • נושאים 5
    • פוסטים 15
    • קבוצות 0

    פוסטים

    פוסטים אחרונים הגבוה ביותר שנוי במחלוקת
    • RE: שלוחת API שמשום מה מריץ את הקוד פעמיים.

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

      הסתדר!

      פורסם בעזרה הדדית למשתמשים מתקדמים
      ל
      לעיתים נדירות
    • שלוחת API שמשום מה מריץ את הקוד פעמיים.

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

      <?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 פעמיים נתונים (מה שמבלבל את הנתונים לפעם הבאה).

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

      פורסם בעזרה הדדית למשתמשים מתקדמים
      ל
      לעיתים נדירות