GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   PHP Help Needed :) (https://gfy.com/showthread.php?t=1043603)

Mamassita 10-28-2011 07:13 PM

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 10-28-2011 07:21 PM

dont think you use == for a boolean

try:

if($paid = false)

Mamassita 10-28-2011 07:23 PM

Quote:

Originally Posted by FlexxAeon (Post 18522544)
dont think you use == for a boolean

try:

if($paid = false)

Work like a charm :)

Thanks a lot :thumbsup

Aric 10-28-2011 07:32 PM

Quote:

Originally Posted by FlexxAeon (Post 18522544)
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.

VladS 10-28-2011 07:35 PM

PHP Code:

if(!$paid


marlboroack 10-28-2011 07:38 PM

PHP Code:

my cock is huge 


FlexxAeon 10-28-2011 07:39 PM

Quote:

Originally Posted by Aric (Post 18522556)
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

Mamassita 10-28-2011 07:40 PM

Quote:

Originally Posted by Aric (Post 18522556)
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 :(

blackmonsters 10-28-2011 08:03 PM

Quote:

Originally Posted by Mamassita (Post 18522547)
Work like a charm :)

Thanks a lot :thumbsup

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!";
}

?>

blackmonsters 10-28-2011 08:04 PM

Quote:

Originally Posted by flexxaeon (Post 18522564)
if it's under an if condition it's not setting a value

stfu!

....

raymor 10-28-2011 08:09 PM

Quote:

Originally Posted by Aric (Post 18522556)
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";
}

blackmonsters 10-28-2011 08:19 PM

Quote:

Originally Posted by raymor (Post 18522596)
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!!!!!!!!!!!!!!!!!!!!!!!!!!!";
}

?>

VladS 10-28-2011 08:24 PM

Quote:

Originally Posted by Gsx-R (Post 18522558)
PHP Code:

if(!$paid


You can also do this.

PHP Code:

if(!isset($paid)) 


FlexxAeon 10-28-2011 08:28 PM

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

Quote:

Originally Posted by blackmonsters (Post 18522593)
stfu!

....

from the dude that still uses tables??? gtfoh

blackmonsters 10-28-2011 08:31 PM

Quote:

Originally Posted by FlexxAeon (Post 18522605)
haha holy shit. i apologize, i was wrong. rookie mistake. doing 3 other things. but...



from the dude that still uses tables??? gtfoh

:1orglaugh

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

:1orglaugh

Zoxxa 10-28-2011 08:35 PM

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?

FlexxAeon 10-28-2011 08:47 PM

Quote:

Originally Posted by blackmonsters (Post 18522607)
:1orglaugh

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

:1orglaugh

:1orglaugh

Kiopa_Matt 10-28-2011 09:11 PM

Quote:

Originally Posted by FlexxAeon (Post 18522564)
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.

Carmen80 10-28-2011 10:15 PM

Quote:

Originally Posted by Gsx-R (Post 18522604)
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';
    }    



Tempest 10-28-2011 11:26 PM

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 ){

Brujah 10-28-2011 11:49 PM

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

loopardo 10-29-2011 12:06 AM

that was intense...

mikke 10-29-2011 03:35 AM

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);

grumpy 10-29-2011 04:23 AM

thats a lot of wrong adivce, next time ask you quetsion at www.stackoverflow.com

Emil 10-29-2011 04:31 AM

Quote:

Originally Posted by marlboroack (Post 18522562)
PHP Code:

my cock is huge 


Doesn't seem to work.

mafia_man 10-29-2011 01:12 PM

Quote:

Originally Posted by Gsx-R (Post 18522604)
You can also do this.

PHP Code:

if(!isset($paid)) 


The only guy on the thread who knows what he is talking about.

raymor 10-29-2011 05:01 PM

Quote:

Originally Posted by Brujah (Post 18522778)
Oh shit this is hilarious. Don't take code advice from GFY anymore!


Hey it's about like us circa 1997.

Mamassita 10-30-2011 11:34 PM

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

Where's konrad :(

Solace 11-29-2011 08:54 PM

First time I have seen code tags used here

biskoppen 11-29-2011 10:07 PM

I'm just here for the cocks

FlexxAeon 11-29-2011 10:26 PM

noooooo my bane is back from the dead! :1orglaugh

haha......wow. don't drink and code :2 cents:


All times are GMT -7. The time now is 09:36 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123