Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts

    Please Check My code .Cant find the error

    Hello

    I have this Code , to enable , Disable Comment . . The Disable is working But the Disable Dose not , i get the OK Message but when i check the Table it did not get uodated with the New value ..

    This suppose to update the Com filed with 0,1 ... and update the time also ..

    when call the file for disable , it works and the filed get updated with new valuse , But the disable dose not work .. and no errors comes back so i cant figuer out why not .. However it works ok in the localhost , it just when i put it on my live site ..

    PHP Code:
    <?php
       $date 
    time();
         
    $id HtmlSpecialchars($_GET['id']);
         
       if (
    HtmlSpecialchars($_GET['action']) == "disable"){

        
     
    $query =mysql_query("UPDATE  ".$DB->prefix("test")." SET com='0' , date='$date' WHERE id='$xid' ")
      or die(
    "Could Not update the Mysql Table");
        if (!
    $query){

         echo 
    "error";
      }else{

         echo 
    "disabled";
          }
       }
        if (
    HtmlSpecialchars($_GET['action']) == "enable"){

     
    $data =mysql_query("UPDATE  ".$DB->prefix("test")." SET com='1' , date='$date' WHERE id='$xid' ")
      or die(
    "Could Not update the Mysql Table");

      if (!
    $data){
             echo 
    "error";

      }else{
              echo 
    "enable";
    }
    }
    ?>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Sorry which isn't working?
    BTW, these blocks are pointless:
    PHP Code:
        if (!$query){

         echo 
    "error";
      }else{

         echo 
    "disabled";
          } 
    $query and $data later will never be false; if they were the die would have kicked in.

    Aside from $xid not existing, it looks fine. Chances are it doesn't work because these variables are incorrect and you cannot update a field with an id value of nothing (unless such a record exists of course).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    ajloun (02-10-2010)

  • #3
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    You ought to be running intval on the $id too, rather than what appears to be some variant of htmlspecialchars.

    Code:
    $id = intval($_GET['id']);

  • Users who have thanked MattF for this post:

    ajloun (02-10-2010)

  • #4
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    thx Guys ..i replaced it with intval and fixed the xid .., still won't update the com filed .. however it dose update the date..
    Last edited by ajloun; 02-10-2010 at 12:58 AM.

  • #5
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    If it's updating the date field, then there's no reason why the com field should remain untouched unless the queries are running in the opposite order to how you're expecting, i.e: the disable block is being called instead of enable and vice versa.

    Add an echo/print after the if clauses to check whether disable/enable are called respectively when requested.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •