Its been a while but im stuck. Below is a snippet of some code that executes during server side validation. I need to build in a check routine to check that the "user" has enough "credits" before deducting the value. Any help would be appreciated.
Thanks, Brad
<?php
if($_POST['slc_reward'] == 1){
$database =& JFactory::getDBO();
$user =& JFactory::getUser();
$query = "UPDATE `jos_users` SET `credits` = `credits`-1 WHERE `id` = '".$user->id."'; ";
$database->setQuery($query);
$database->query();
} else {
echo 'You selected an invalid option.';
}
?>
Thanks, Brad
Hi brad2k10,
You could do a conditional update in the MySQL but I can't see any way of getting the info back. So probably better to use two MySQL queries; the first one to check if there is enough credit; the second to update the credit if there is.
Bob
You could do a conditional update in the MySQL but I can't see any way of getting the info back. So probably better to use two MySQL queries; the first one to check if there is enough credit; the second to update the credit if there is.
Bob
Hi Bob.
Firstly thanks for the swift reply as always. Noticed your books out at last🙂 will put an order in when i get chance.
Rite im thinking something along the lines of this.
I have user put in an item code and then i put together a query that matches that item to an item in a table and pulls through the "credit cost" for that item and then querys that figure against the users credits in another table. If say the user dosent have enough credits how will i be able to interpret the return value from SQL so i can thro a user message up saying not enough credits?
Firstly thanks for the swift reply as always. Noticed your books out at last🙂 will put an order in when i get chance.
Rite im thinking something along the lines of this.
I have user put in an item code and then i put together a query that matches that item to an item in a table and pulls through the "credit cost" for that item and then querys that figure against the users credits in another table. If say the user dosent have enough credits how will i be able to interpret the return value from SQL so i can thro a user message up saying not enough credits?
This topic is locked and no more replies can be posted.