Help with understanding what this says/does

Many thanks again for all the assistance.
It all works successfully. (although I removed this:

}else{
$error = "Sell video system turned off";

I didn’t think it was neccessary (let me know if you think it is neccessary).

After the lines:

	$error = "lack of funds error";
			}

I tried to add this:

if ($_POST['set_p_v'] == 0 && $wallet >=1)){
$_POST['set_p_v'] == 0;

without success.
I look forward to your comments

What would be the reason for that?
There is nothing wrong with having an IF condition saying

if ($_POST['set_p_v'] == 0 && $wallet >=1)){
//Some action
}

But just making a comparison statement, e.g. $_POST['set_p_v'] == 0; by itself DOES NOTHING so I am not sure what “without success” might be.

The fact that you removed the $error = "Sell video system turned off"; section just means that the user just won’t know what happened or why it’s not working when the system is turned off.

Thanks.
I’m trying to have the “//Some action” be: allow an 0 entry in the Price field and no longer show an error for that.
any additional guidance with that is welcomed

From post #40 above.

if (empty($error) && $_POST['set_p_v'] == 0 && $wallet <1){
	//$error = $lang->lack_of_funds_error;
	$error = "lack of funds error";
}

It says IF the price is 0 AND wallet is less then 1 throw “lack of funds” error. So if you have some funds in the wallet, this section should not trigger an error message.

If is a “price error” you are talking about then I ask you what does $pt->config->admin_com_sell_videos return?

Your condition says
IF $pt->config->com_type == 0 AND “the price” is less than or equal to $pt->config->admin_com_sell_videos throw error…

I am not sure why you would have to set a price higher than $pt->config->admin_com_sell_videos but that is what it wants.

What was the intent of writing this section of code to check against admin_com_sell_videos?

Thanks again. Sorry for my confusion.
Regarding “if you have some funds in the wallet, this section should not trigger an error message”,
I have added some funds in the wallet and the ‘lack of funds’ error still displays.
Any ideas as to not show the error if funds are in the wallet, are appreciated.

if (empty($error) && $_POST['set_p_v'] == 0 && $wallet <1){

Where on this line do you see any part that would result in TRUE if there are funds defined in the variable $wallet? You haven’t shown where this variable is defined or even tests you’ve done by actually echoing $wallet to make sure it holds the value you are touting. Being a coder also takes some responsibility of self testing by knowing exactly what each part represents and the values they hold.

You could say"I put 20 into the $wallet and echoing $wallet shows that I have 20 so I am not sure why $wallet < 1 would be TRUE." In contrast, if you put 20 into “the wallet”, but the variable $wallet is undefined or incorrectly defined and empty then $wallet < 1 would be TRUE because $wallet holds no value.

1 Like

Much thanks again. Yes, my oversight… with the wallet defined it proceeds with funding and displays funding error without funds. I greatly appreciate your guidance and expertise…

1 Like

I don’t know what the purpose of it either but we help when we can.

Thanks again for all the previous help.
Another similar page in script allows a user to edit the price field:

		    if (is_numeric($_POST['set_p_v']) && $_POST['set_p_v'] > -1) {
	            $data_update['sell_video'] = PT_Secure($_POST['set_p_v']);
	        }

To try to add a modification, I added this below that line, trying to display an error if the line is blank:

	       else{
	        if ($_POST['set_p_v'] == "") {
			$error = "enter_an_amount";
			}

with no success, The Edit Form does not proceed or display an error.
Any guidance is welcomed.

Running a little test page with your conditions shows the error message as expected. In the future if you could tell what you entered into the form that might help.

if($_SERVER["REQUEST_METHOD"] == "POST"){
 
	if (is_numeric($_POST['set_p_v']) && $_POST['set_p_v'] > -1) {
		$data_update['sell_video'] = PT_Secure($_POST['set_p_v']);
	}
	else{
		if ($_POST['set_p_v'] == "") {
			$error = "enter_an_amount";
		}
	}
}

if(!empty($error)){
	echo $error;
}
?>
<form action="" method="post">
	<input type="text" name="set_p_v" />
	<input type="submit" value="submit" />
</form>

I would avoid using else as a condition for form processing. There should always be check that there are no errors before moving forward and in this example we are using $error to define error message so in our IF condition(s) we should look for empty($error). So I would stack all our checks above any place a form is approved. For example.

if($_SERVER["REQUEST_METHOD"] == "POST"){ 
	
 	if ($_POST['set_p_v'] == "") {
		$error = "enter_an_amount";
	}
	if (empty($error) && is_numeric($_POST['set_p_v']) && $_POST['set_p_v'] > -1) {
		$data_update['sell_video'] = PT_Secure($_POST['set_p_v']);
	}
}	

Someone could enter B and nothing happens so you could always add other checks above the final IF condition as long as you are checking for empty($error).

if($_SERVER["REQUEST_METHOD"] == "POST"){ 
	
 	if ($_POST['set_p_v'] == "") {
		$error = "enter_an_amount";
	}
	if (empty($error) && !is_numeric($_POST['set_p_v']) && $_POST['set_p_v'] != "") {
		$error = "amount must be a number";
	}
	if (empty($error) && is_numeric($_POST['set_p_v']) && $_POST['set_p_v'] > -1) {
		$data_update['sell_video'] = PT_Secure($_POST['set_p_v']);
	}
} 
1 Like

Thank you again.
So, all aspects of this Form work successfully, except it displays the ‘please check Form details’ error upon entering a 0 in the price field. I’ve tried many things, but I can’t seem to get it to display “not enough money” error. So, I can’t tell if “//lack of funds” portion is even functioning at all.

if (empty($_POST['title']) || empty($_POST['description']) || empty($_POST['tags']) || empty($_POST['video-id']) || empty($_POST['set_p_v'])) {
	    $error = $lang->please_check_details;
	}

if (($pt->config->sell_videos_system == 'on' && (($pt->config->who_sell == 'pro_users' && $pt->user->is_pro) || $pt->config->who_sell == 'users' || $pt->user->admin)) && !empty($_POST['set_p_v'])) {
	  if (!empty($_POST['set_p_v'])  || (in_array('set_p_v', array_keys($_POST)) && $_POST['set_p_v'] < 0)) {

if (!is_numeric($_POST['set_p_v']) || $_POST['set_p_v'] < 0 || (($pt->config->com_type == 0 && $_POST['set_p_v'] <= $pt->config->admin_com_sell_videos)) ) {
	$error = $lang->video_price_error." ".($pt->config->com_type == 0 ? $pt->config->admin_com_sell_videos : 0);
}

// lack of funds error
if ($_POST['set_p_v'] == 0 && $wallet <1){
$error = "not enough money";
	    }
       }
}

any additional guidance is welcomed.

Remove || empty($_POST['set_p_v']) from the first IF condition as ZERO IS EMPTY.

Thanks again.
I have removed the || empty($POST[ ‘set_p_v’]) from the first IF condition, like so:

if (empty($_POST['title']) || empty($_POST['description']) || empty($_POST['tags']) || empty($_POST['video-id'])) {

when tested with user’s wallet amount: 0. And entering 0 in the price field, it displays “successful update” and the change proceeds successfully. I want it to display “not enough money”.

So, when I change back to:

if (empty($_POST['title']) || empty($_POST['description']) || empty($_POST['tags']) || empty($_POST['video-id']) || empty($_POST['set_p_v'])) {

and re-test, It displays “check Form details” instead of “not enough money”. My //lack of funds code may be incorrect and/or it may be affected by these lines towards the bottom of the file:

		    if (is_numeric($_POST['set_p_v']) && $_POST['set_p_v'] > -1) {
	            $data_update['sell_video'] = PT_Secure($_POST['set_p_v']);
	        }

I look forward to comments/suggestions

Why is this IF condition, which as I understand it is dealing with permissions of sale anywhere near itemized form checking?

if (($pt->config->sell_videos_system == 'on' && (($pt->config->who_sell == 'pro_users' && $pt->user->is_pro) || $pt->config->who_sell == 'users' || $pt->user->admin)) && !empty($_POST['set_p_v'])) {

Also the condition " && !empty($_POST['set_p_v'])" should NOT be in this line at all.
This is a general SALE IF condition that would wrap around processing code. I would think it should be like so.

if (($pt->config->sell_videos_system == 'on' && (($pt->config->who_sell == 'pro_users' && $pt->user->is_pro) || $pt->config->who_sell == 'users' || $pt->user->admin))) {
	// SELL VIDEO SECTION - ALL PROCESSING CODE GOES HERE 
	
}else{
	$error = "VIDEO SALES ARE OFFLINE";	
}

I am not sure what this condition is for. Is it a general SALE condition or a user input check. It is saying:
IF com_type equals 0 and user input is less than or equal to admin_com_sell_videos.
What us the relationship between admin_com_sell_videos and the amount entered into set_p_v?

$pt->config->com_type == 0 && $_POST['set_p_v'] <= $pt->config->admin_com_sell_videos

In any case the final “approval” must pass the empty($error) condition of all previous checks so you need to stack all your checks above the final condition.
Something like this.

if (($pt->config->sell_videos_system == 'on' && (($pt->config->who_sell == 'pro_users' && $pt->user->is_pro) || $pt->config->who_sell == 'users' || $pt->user->admin))) {
	// SELL VIDEO SECTION - ALL PROCESSING CODE GOES HERE 
	
	//Form details
	if (empty($_POST['title']) || empty($_POST['description']) || empty($_POST['tags']) || empty($_POST['video-id']))) {
		$error = $lang->please_check_details;
	}
	//Empty input
	if (empty($error) && $_POST['set_p_v'] == "") {
		$error = "enter_an_amount";
	}
	//Numeric check
	if (empty($error) && !is_numeric($_POST['set_p_v']) && $_POST['set_p_v'] != "") {
		$error = "amount must be a number";
	}
	// Your price error condition
	if (empty($error) && (!is_numeric($_POST['set_p_v']) || $_POST['set_p_v'] < 0 || (($pt->config->com_type == 0 && $_POST['set_p_v'] <= $pt->config->admin_com_sell_videos)))) {
		$error = $lang->video_price_error." ".($pt->config->com_type == 0 ? $pt->config->admin_com_sell_videos : 0);
	}
	//Wallet check
	if (empty($error) && $_POST['set_p_v'] == 0 && $wallet <1){
		$error = "not enough money";
	} 
	//After passing all checks the final check is made	
	if (empty($error) && is_numeric($_POST['set_p_v']) && $_POST['set_p_v'] > -1) {
		$data_update['sell_video'] = PT_Secure($_POST['set_p_v']);
	}
	
}else{
	$error = "VIDEO SALES ARE OFFLINE";	
}

Many, many thanks.
All aspects are successful and it successfully displays “not enough money” when the ‘wallet’ is empty,
but also displays “not enough money” when the ‘wallet’ has, for example, 2 in it.
Ultimately, success would be if upon entering 0 in the price field, with any amount in the ‘wallet’ equal to or greater than 1, the Form submits/proceeds/succeeds.
I look forward to any idea on this…
thanks again

Then you need to check that $wallet has expected value as this error is shown when $wallet is less than 1, not when $wallet is 2.

Thanks for your reply. I have researched ‘expected value’, but don’t know how to apply it in this case.
Any additional guidance is appreciated.

You could always add the wallet amount to the error message at least for testing what the value is.

$error = "not enough money in Wallet: ".$wallet;

Thank you for your suggestion.
The result displayed is:

not enough money in Wallet:

also,
db > table > wallet shows this:

I look forward to your comments/suggestions

Then you need to look into where $wallet is defined. You said in post #51 that this code was for the user to edit the price. If that is so, do you even need these wallet checks? If it is a “buyer form section”, Is this the same issue as #46 ,#47? Show the code where you get the buyer information and define $wallet. Wasn’t it something like:

$wallet = $user->wallet;
1 Like