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
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 < 1would be TRUE because $wallet holds no value.
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…
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.
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.
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']);
}
}
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.
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”.
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:
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?
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 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: