How to redirect

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bytM3
    New Member
    • May 2021
    • 6

    How to redirect

    Will you tell what I'm doing wrong. It goes straight to "expiredpage.ht ml" even though the value
    of "expiry" is more than 0. I keep studying redirection and variable definition but nothing works. It does
    update.
    Code:
    <?php
    $link = mysqli_connect("localhost", "root", "", "prerentdb"); 
    // Check connection
    if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); }
    
    $id='id';
    $expiry='expiry';
    
    $sql = "UPDATE numbers SET expiry=$expiry- 1 where id=$id";
    if(mysqli_query($link, $sql)){ echo "expiry was updated successfully."; } 
    else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); }
    
    if ($expiry == 0) { 
    header("location:expiredpage.html");
    // window.location.href = 'expiredpage.html';
    // $(location).attr('href', 'expiredpage.html')
     } 
    
    else  { 
     header("location:sysnav.html");
    //window.location.href = 'sysnav.html';
    //  $(location).attr('href', 'sysnav.html')
     } 
    // Close connection
    mysqli_close($link);
    ?>
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    bytM3
    Will you tell what I'm doing wrong. It goes straight to "expiredpage.ht ml" even though the value
    of "expiry" is more than 0. I keep studying redirection and variable definition but nothing works. It does
    update.
    Src https://wiki.php.net/rfc/string_to_n...n#introduction
    Comparisons between strings and numbers using == and other non-strict comparison operators currently work by casting the string to a number, and subsequently performing a comparison on integers or floats. This results in many surprising comparison results, the most notable of which is that 0 == "foobar" returns true. This RFC proposes to make non-strict comparisons more useful and less error prone, by using a number comparison only if the string is actually numeric. Otherwise the number is converted into a string, and a string comparison is performed.

    Comment

    Working...