1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

why the result

Discussion in 'PHP' started by pshaw, Feb 19, 2023.

  1. #1
    Hi, please tell me why the result
    --------------------------------
    the code:
    <?php
    $link = mysqli_connect("localhost", "root", "", "homedb");
    // Check connection
    if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); }
    
    //MySqli Select Query
    $results = mysqli_query($link, "SELECT `id`, `expiry` FROM `ctltbl`");
    
    $row = $results->fetch_row();
    
    $id = $row[0];
    $expiry = (int) $row[1];
    
    if ($expiry > 0) {
      $sql = "UPDATE `ctltbl` SET `expiry` = $expiry - 1 where `id` = $id";
    
      if (mysqli_query($link, $sql)) {
      echo ".";
      } else {
      echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
      }
    
    header("location:sysnav.html");
    }
    
    echo "We're sorry but your contract has expired. Contact us immediately at uCanLease@yahoo.com";
    ?>
    PHP:
    --------------------------------------------
    result;
    fetch_row(); $id = $row[0]; $expiry = (int) $row[1]; if ($expiry > 0) {
    $sql = "UPDATE `ctltbl` SET `expiry` = $expiry - 1 where `id` = $id";
    if (mysqli_query($link, $sql)) { echo "."; } else {
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); }
    header("location:sysnav.html"); } echo "We're sorry but your contract has expired. Contact us
    immediately at uCanLease@yahoo.com"; ?>
    Code (markup):

     
    Last edited by a moderator: Feb 21, 2023
    pshaw, Feb 19, 2023 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,641
    Likes Received:
    4,486
    Best Answers:
    123
    Trophy Points:
    665
    #2
    There's some odd stuff happening here but let's start with this
    $sql = "UPDATE `ctltbl` SET `expiry` = $expiry - 1 where `id` = $id";
    PHP:
    if you echo it out and put that straight into something like phpMyAdmin does the query run?
    Have you tried writing it as
    $sql = "UPDATE `ctltbl` SET `expiry` = DATE_ADD({$expiry},INTERVAL -1) where `id` = {$id}";
    PHP:
     
    sarahk, Feb 21, 2023 IP