PHP Help Needed :)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mamassita
    Confirmed User
    • Nov 2009
    • 252

    #1

    PHP Help Needed :)

    Building a paid module for a custom tube script, but i'm getting this error


    Notice: Undefined variable: paid in /home/nakedmov/public_html/xxx/video.php on line 179

    Notice: Undefined variable: paid in /home/nakedmov/public_html/xxx/video.php on line 213


    Line 179 to 187
    PHP Code:
    if($paid == false){
        if(isset($users_credits)){
            if($credits > $users_credits){
                $errors[] = 'Not enough credits for this action. Visit credits page from your profile to charge up your account!';
            }        
        } else {
            $errors[] = 'You need to login before you can watch this video';
        }    
    } 
    
    Line 213
    PHP Code:
    $smarty->assign('paid',$paid); 
    
    Anyone know what i've done wrong ?

    Thanks
  • FlexxAeon
    Confirmed User
    • May 2003
    • 3765

    #2
    dont think you use == for a boolean

    try:

    if($paid = false)
    flexx [dot] aeon [at] gmail

    Comment

    • Mamassita
      Confirmed User
      • Nov 2009
      • 252

      #3
      Originally posted by FlexxAeon
      dont think you use == for a boolean

      try:

      if($paid = false)
      Work like a charm

      Thanks a lot

      Comment

      • Aric
        Confirmed User
        • Sep 2002
        • 1209

        #4
        Originally posted by FlexxAeon
        dont think you use == for a boolean

        try:

        if($paid = false)
        I'm no expert, but that is wrong? You just assigned a value to $paid, which of course got rid of his PHP notices.

        The PHP notices are displayed because $paid has no value set before the conditional.
        Awesome cloud hosting by DigitalOcean

        Comment

        • VladS
          Available for Coding Work
          • Jun 2008
          • 1459

          #5
          PHP Code:
          if(!$paid) 
          
          <developer> MechBunny / KVS / PHP / MySQL / HTML5 / CSS3 / jQuery
          Email: vlad [at] dangerouscoding.com
          Telegram: @dangerouscoding

          Comment

          • marlboroack
            So Fucking Banned
            • Jul 2010
            • 9327

            #6
            PHP Code:
            my cock is huge 
            

            Comment

            • FlexxAeon
              Confirmed User
              • May 2003
              • 3765

              #7
              Originally posted by Aric
              I'm no expert, but that is wrong? You just assigned a value to $paid, which of course got rid of his PHP notices.

              The PHP notices are displayed because $paid has no value set before the conditional.
              if it's under an if condition it's not setting a value
              flexx [dot] aeon [at] gmail

              Comment

              • Mamassita
                Confirmed User
                • Nov 2009
                • 252

                #8
                Originally posted by Aric
                I'm no expert, but that is wrong? You just assigned a value to $paid, which of course got rid of his PHP notices.

                The PHP notices are displayed because $paid has no value set before the conditional.
                yeah seem there's no notices anymore

                Comment

                • blackmonsters
                  Making PHP work
                  • Nov 2002
                  • 20961

                  #9
                  Originally posted by Mamassita
                  Work like a charm

                  Thanks a lot
                  No it didn't.

                  Run these two scripts :

                  <?php

                  $paid = false;
                  if($paid = false) {
                  echo "This really works!";

                  }
                  else {
                  echo "No No No No!";
                  }

                  ?>


                  -------------

                  <?php

                  $paid = false;
                  if($paid == false) {
                  echo "This really works!";

                  }
                  else {
                  echo "No No No No!";
                  }

                  ?>
                  Free Open Source Live Aggregated Cams Script (FOSLACS)

                  Comment

                  • blackmonsters
                    Making PHP work
                    • Nov 2002
                    • 20961

                    #10
                    Originally posted by flexxaeon
                    if it's under an if condition it's not setting a value
                    stfu!

                    ....
                    Free Open Source Live Aggregated Cams Script (FOSLACS)

                    Comment

                    • raymor
                      Confirmed User
                      • Oct 2002
                      • 3745

                      #11
                      Originally posted by Aric
                      I'm no expert, but that is wrong? You just assigned a value to $paid, which of course got rid of his PHP notices.

                      The PHP notices are displayed because $paid has no value set before the conditional.
                      Yep, $paid = false sets $paid to false.
                      The warning goes away because it's perfectly legal code, but it's also perfectly useless - it will always be true. To confirm, try this:

                      $paid = 1;
                      if ($paid = false) {
                      echo "oops, wrong answer";
                      }
                      For historical display only. This information is not current:
                      support&#64;bettercgi.com ICQ 7208627
                      Strongbox - The next generation in site security
                      Throttlebox - The next generation in bandwidth control
                      Clonebox - Backup and disaster recovery on steroids

                      Comment

                      • blackmonsters
                        Making PHP work
                        • Nov 2002
                        • 20961

                        #12
                        Originally posted by raymor
                        Yep, $paid = false sets $paid to false.
                        The warning goes away because it's perfectly legal code, but it's also perfectly useless - it will always be true. To confirm, try this:

                        $paid = 1;
                        if ($paid = false) {
                        echo "oops, wrong answer";
                        }
                        Exactly :

                        <?php

                        //$paid is not defined yet

                        if($paid = false) {
                        echo "paid is false";
                        }
                        //$paid was set to false above

                        if($paid == false) {
                        echo "That's really FUCKED UP!!!!!!!!!!!!!!!!!!!!!!!!!!!";
                        }

                        ?>
                        Free Open Source Live Aggregated Cams Script (FOSLACS)

                        Comment

                        • VladS
                          Available for Coding Work
                          • Jun 2008
                          • 1459

                          #13
                          Originally posted by Gsx-R
                          PHP Code:
                          if(!$paid) 
                          
                          You can also do this.

                          PHP Code:
                          if(!isset($paid)) 
                          
                          <developer> MechBunny / KVS / PHP / MySQL / HTML5 / CSS3 / jQuery
                          Email: vlad [at] dangerouscoding.com
                          Telegram: @dangerouscoding

                          Comment

                          • FlexxAeon
                            Confirmed User
                            • May 2003
                            • 3765

                            #14
                            haha holy shit. i apologize, i was wrong. rookie mistake. doing 3 other things. but...

                            Originally posted by blackmonsters
                            stfu!

                            ....
                            from the dude that still uses tables??? gtfoh
                            flexx [dot] aeon [at] gmail

                            Comment

                            • blackmonsters
                              Making PHP work
                              • Nov 2002
                              • 20961

                              #15
                              Originally posted by FlexxAeon
                              haha holy shit. i apologize, i was wrong. rookie mistake. doing 3 other things. but...



                              from the dude that still uses tables??? gtfoh


                              I use tables because I know what the fuck I'm doing.

                              Free Open Source Live Aggregated Cams Script (FOSLACS)

                              Comment

                              • Zoxxa
                                Confirmed User
                                • Feb 2011
                                • 1026

                                #16
                                Your original code should work fine. The problem seems to be getting the boolean value assigned to the variable in the first place. Your error message states "Undefined variable", meaning it probably has no value. Have you echo'd out the value of $paid before the if statement to see if it has any value or is NULL?
                                Last edited by Zoxxa; 10-28-2011, 07:39 PM.
                                [email protected]
                                ICQ: 269486444
                                ZoxEmbedTube - Build unlimited "fake" tubes with this easy 100% unencoded CMS!

                                Comment

                                • FlexxAeon
                                  Confirmed User
                                  • May 2003
                                  • 3765

                                  #17
                                  Originally posted by blackmonsters


                                  I use tables because I know what the fuck I'm doing.

                                  flexx [dot] aeon [at] gmail

                                  Comment

                                  • Kiopa_Matt
                                    Confirmed User
                                    • Oct 2007
                                    • 1448

                                    #18
                                    Originally posted by FlexxAeon
                                    if it's under an if condition it's not setting a value
                                    Yes, it does. Test it and see. PHP executes what's inside the brackets first, and since it successfully assigned $paid as false, the conditional passes.
                                    xMarkPro -- Ultimate Blog Network Management
                                    Streamline your marketing operations. Centralize management of domains, pages, Wordpress blogs, sponsors, link codes, media items, sales and traffic statistics, plus more!

                                    Comment

                                    • Carmen80
                                      Confirmed User
                                      • Sep 2010
                                      • 207

                                      #19
                                      Originally posted by Gsx-R
                                      You can also do this.

                                      PHP Code:
                                      if(!isset($paid)) 
                                      
                                      That is plain wrong. You're checking if the variable exists, not if the value is true or false.

                                      --

                                      The real solution:

                                      PHP Code:
                                      if(!isset($paid) || !$paid){
                                          if(isset($users_credits)){
                                              if($credits > $users_credits){
                                                  $errors[] = 'Not enough credits for this action. Visit credits page from your profile to charge up your account!';
                                              }        
                                          } else {
                                              $errors[] = 'You need to login before you can watch this video';
                                          }    
                                      } 
                                      
                                      You should really considering lowering your error reporting level. This should be done at the top of the script, and the script can look like this. Less messy and actually faster.
                                      PHP Code:
                                      error_reporting(E_ALL ^ E_NOTICE); // put this on top of the script, preferably inside your top configuration include file
                                      
                                      if(!$paid){
                                          if(isset($users_credits)){
                                              if($credits > $users_credits){
                                                  $errors[] = 'Not enough credits for this action. Visit credits page from your profile to charge up your account!';
                                              }        
                                          } else {
                                              $errors[] = 'You need to login before you can watch this video';
                                          }    
                                      } 
                                      
                                      Last edited by Carmen80; 10-28-2011, 09:19 PM.
                                      It's all just a strange dream..

                                      Comment

                                      • Tempest
                                        Too lazy to set a custom title
                                        • May 2004
                                        • 10217

                                        #20
                                        Oh good lord.... lol.. The "proper" way.

                                        Code:
                                        if( !isset($page) || $page !== true ){
                                        That assumes that $page will contain a proper php boolean type.. And yes, the extra = is not a typo because it doesn't just check the value but also the "type". However, if it's a 0/1 then it should just be

                                        Code:
                                        if( !isset($page) || $page != 1 ){

                                        Comment

                                        • Brujah
                                          Beer Money Baron
                                          • Jan 2001
                                          • 22157

                                          #21
                                          Oh shit this is hilarious. Don't take code advice from GFY anymore!

                                          Comment

                                          • loopardo
                                            Registered User
                                            • Aug 2008
                                            • 81

                                            #22
                                            that was intense...
                                            ___

                                            Comment

                                            • mikke
                                              Confirmed User
                                              • Jan 2010
                                              • 1327

                                              #23
                                              Code:
                                              if(empty($paid)){
                                                  if(isset($users_credits)){
                                                      if($credits > $users_credits){
                                                          $errors[] = 'Not enough credits for this action. Visit credits page from your profile to charge up your account!';
                                                      }        
                                                  } else {
                                                      $errors[] = 'You need to login before you can watch this video';
                                                  }    
                                              }
                                              also..

                                              Code:
                                              $smarty->assign('paid', !empty($paid)?$paid:false);
                                              icq: 395 294 346
                                              http://www.adultsubmitter.eu - submit any adult site to 20 directories from 1 form!
                                              now 20 domains!
                                              http://www.porndeals.eu http://www.ebonybangbros.com

                                              Comment

                                              • grumpy
                                                Too lazy to set a custom title
                                                • Jan 2002
                                                • 9870

                                                #24
                                                thats a lot of wrong adivce, next time ask you quetsion at www.stackoverflow.com
                                                Don't let greediness blur your vision | You gotta let some shit slide
                                                icq - 441-456-888

                                                Comment

                                                • Emil
                                                  Confirmed User
                                                  • Feb 2007
                                                  • 5658

                                                  #25
                                                  Originally posted by marlboroack
                                                  PHP Code:
                                                  my cock is huge 
                                                  
                                                  Doesn't seem to work.
                                                  Free 🅑🅘🅣🅒🅞🅘🅝🅢 Every Hour (Yes, really. Free ₿itCoins.)
                                                  (Signup with ONLY your Email and Password. You can also refer people and get even more.)

                                                  Comment

                                                  • mafia_man
                                                    Confirmed User
                                                    • Jul 2005
                                                    • 1965

                                                    #26
                                                    Originally posted by Gsx-R
                                                    You can also do this.

                                                    PHP Code:
                                                    if(!isset($paid)) 
                                                    
                                                    The only guy on the thread who knows what he is talking about.
                                                    I'm out.

                                                    Comment

                                                    • raymor
                                                      Confirmed User
                                                      • Oct 2002
                                                      • 3745

                                                      #27
                                                      Originally posted by Brujah
                                                      Oh shit this is hilarious. Don't take code advice from GFY anymore!

                                                      Hey it's about like us circa 1997.
                                                      For historical display only. This information is not current:
                                                      support&#64;bettercgi.com ICQ 7208627
                                                      Strongbox - The next generation in site security
                                                      Throttlebox - The next generation in bandwidth control
                                                      Clonebox - Backup and disaster recovery on steroids

                                                      Comment

                                                      • Mamassita
                                                        Confirmed User
                                                        • Nov 2009
                                                        • 252

                                                        #28
                                                        Damn guys i wont buy any shit you made...

                                                        Where's konrad

                                                        Comment

                                                        • Solace
                                                          So Fucking Banned
                                                          • Nov 2011
                                                          • 995

                                                          #29
                                                          First time I have seen code tags used here

                                                          Comment

                                                          • biskoppen
                                                            Confirmed User
                                                            • Mar 2003
                                                            • 5809

                                                            #30
                                                            I'm just here for the cocks
                                                            Submit my videos to make bank, tons of 5 minute videos offered right here

                                                            Comment

                                                            • FlexxAeon
                                                              Confirmed User
                                                              • May 2003
                                                              • 3765

                                                              #31
                                                              noooooo my bane is back from the dead!

                                                              haha......wow. don't drink and code
                                                              Last edited by FlexxAeon; 11-29-2011, 08:31 PM.
                                                              flexx [dot] aeon [at] gmail

                                                              Comment

                                                              Working...