PHP - Help With Checking 'balance' After 'wallet'
I am using a php web video script which allows Users to purchase videos successfully. The purchases are made from the amount available in the Users’ “wallet” (the User can also earn compensation, which gets added to his “balance”.). When there’s not enough available in the “wallet” for the purchase, the script checks and displays a message “not enough money”. I’d like help adding the ability where the script first checks the “wallet” amount, and if empty will then check the “balance” amount, and use a required amount from the balance, and if both are empty, then the “not enough money” appears. Here’s the portion of the code that I believe needs the modification: // get cost video $db->where('name', 'video_play_price'); $db_cost = $db->getOne('config'); $video_cost = (float)$db_cost->value; $count_video = count($id_array); $user_id = $user->id; $wallet = (float)str_replace(',', '', $user->wallet); $amout = 0; foreach ($id_array as $id) { $video_id = (int)PT_Secure($id); // get video data $video = $db->where('id', $id)->getOne(T_VIDEOS); $amout += $video->video_play_price?$video->video_play_price:$video_cost; } // $amout = $video_cost * $count_video; $charge = ( $video_cost *0.50 ); if ($wallet >= $amout) { //$new_wallet = (string)($wallet - $amout); $wallet = (string)($wallet - $amout); $db->startTransaction(); $inserted_records = 0; foreach ($id_array as $id) { $video_id = (int)PT_Secure($id); // $uploader_amount = $video_cost - $charge; //100 - 20% = 80 // get video data $video = $db->where('id', $id)->getOne(T_VIDEOS); $video_cost_new = $video->video_play_price?$video->video_play_price:$video_cost; $uploader_amount = ( $video_cost_new *0.50 ); // add data to paid table $insert_buy = $db->insert('u_paid_videos', [ 'id_user' => $user_id, 'id_video' => $video_id, 'session_key' => $_SESSION['session_key'], 'video_play_price' => (string)$video_cost, 'video_title' => $video->title, 'user_id_uploaded' => $video->user_id, ]); if ($insert_buy) { $inserted_records++; } //add wallet users' video $userwallet = $db->where('id', $video->user_id)->getOne(T_USERS); //$videouserwallet = $userwallet->balance+$video_cost; $videouserwallet = $userwallet->balance+$uploader_amount; $db->where('id', $video->user_id); $update_balance = $db->update(T_USERS, [ // 'wallet' => $videouserwallet, 'balance' => number_format($videouserwallet, 1, '.', ''), ]); } $db->where('id', $user_id); //$update_wallet = $db->update(T_USERS, [ $update_wallet = $db->update(T_USERS, [ 'wallet' => $wallet, ]); if (($inserted_records == $count_video) && $update_wallet) { $db->commit(); echo json_encode([ 'status' => 200 ]); exit(); } else { $db->rollback(); echo json_encode([ 'status' => 400, 'error' => 'Buy process error' ]); exit(); } } else { echo json_encode([ 'status' => 400, 'error_num' => 1, 'error' => 'Not enough money' ]); exit(); } } else { echo json_encode([ 'status' => 400, 'error' => 'Bad Request, Invalid or missing parameter' ]); exit();
Similar TutorialsI have a custom finance management site and within it I can see amount owed paid and total account balance. I have a table called `Transactions` with 8 fields ID - unique post ID UID - User ID name - Name of the person or business amount - amount of the transaction, in the format of -100.00 or +100.00 date category comment delete - default 0 What I want is to check every unique name and add up the totals and if it totals up to a negative send out a email. I already have a PHP script for the user to see this list, I just want to know if there is some way possible to automate this weekly via cron job. Is it possible? Thanks in advanced! Hello, Im making a little script to keep track on how much people have currently earnt on my site. I have everything work but i can't figure out how to work out the current balance At the moment ive got: Code: [Select] $currentbalance = $row['totalpaid'] - $row['points']; Which works untill the points becomes more then the total paid then it starts going in minus. Im sure there's a simple fix but i just can't think of a way. Any help would be great. Thanks hello I am a chemical teacher in the middle school I hope Balancing Chemical Equations via PHP I google some thing perhaps the CML( http://en.wikipedia.org/wiki/Chemical_Markup_Language) may give me a hand. and this one the http://shinkirou.org/blog/2010/11/balancing-chemical-equations-with-linear-algebra/ tells me using the Linear Algebra is a good way how can I Balancing Chemical Equations via PHP( by CML )? is their a demo ? thank you very much~! Hi friends, I am creating a site where users can add credit to their account via Liberty Reserve, and after that their account will automatically be updated with the amount they added so that they can use it to purchase products.. And after any purchase, the amount will be subtracted from their account.. I cant really find a php code to do that... i have done a search on here but still cant find anything close to it.. Can someone kindly help? Thank you I am trying to generate data similar to a running balance for a checkbook. My approach (correct me if there is a better method) is to get the balance from the previous record ID and then add/subtract the new value and create a new total balance. However, I am not havig succes with MAX(id) or last_insert_id -- is one preferable over the other?? if($result = mysqli_query($link, $sql)){ if(mysqli_num_rows($result) > 0){ $sql = "SELECT MAX(id) FROM persons"; echo "<br /<br />"; echo $sql; Please assist. Does anybody have links or scripst on a script where the user has an account with money which decreases as one purchases items. Regards Hello,
I designed (not coded) a finance application for windows phone 8.1 and one of the features that would be ideal is to copy your login steps in order to access your bank account automatically. Yes this does not sound safe or sane. How do I convince app users to use it?
Anyway, I want this access. My rationale is that, the login information would be stored locally and if my phone was hacked then what's the loss in my login steps being hacked... they would probably be encrypted anyway but...
The goal is to be able to open up a clone browser (eg. within the app) and then every step that you take, enter url, login credentials, security questions, pages accessed... the clone browser remembers and then later on as part of the app's function, it would automatically update your balances. I mean I suppose you could come up with the formulas, cash advance fees, interest rates, etc... but at the same time this doesn't seem to be a fixed thing... eg. hard to keep track and get the exact cent amount... or maybe I'm just bad at math
Some things in mind bitmapping, key strokes, string search, number search...
Anyway scripting came to mind, not sure if php or python but
Any thoughts?
So basically I have a site, and on that site, I have a page that submits a form and updates a database. I have it set up so that someone can enter in Multiple values into a textarea, one on each line, and it will submit each of those values as a new row in the database, but for the life of me, I cannot figure out how to check those values against the actual users. It is basically a point system, where the staff can award points users of the site. But at the moment, a Staff member could enter in Jibberish, and it would insert that into the database, but I want it to check my users table to make sure the user exists before it inserts it into the database. here is my code: <?php include 'global.php'; echo $headersidebar; if ($_COOKIE['access'] == $accessstaff) { if(count($_POST)) { $array = preg_split('/(\r?\n)+/', $_POST['studentname']); foreach($array as $students) { $statusmsg = '<center><span style="background: #A6FF9E;">You have successfully submitted points to the database.</span></center>'; mysql_query("INSERT INTO points (giver, receiver, points, category, reason, date, status) VALUES ('{$_COOKIE['username']}', '{$students}', '{$_POST['pointamt']}', '{$_POST['pointcat']}', '{$_POST['pointreason']}', '{$date}', 'Validating')"); } } $addpointspage = $statusmsg . ' <form action="submit_points.php" method="post"> <table class="table" > <tr> <td colspan="10"> <h1><strong><center>Submit Points</center></strong></h1> </td> </tr> <tr> <td colspan="10" rowspan="100"> <center>Please remember to follow the house point limits when submitting house points.</center> </td> </tr> </table> <table class="table"> <tr> <td style="width: 15%;" valign="top"> Student Name:<br> <span style="font-size: 60%;">(List as many as you want; One per Line)</span> </td> <td colspan="10"> <center><textarea name="studentname" cols="60" rows="10"></textarea></center> </td> </tr> <tr> <td style="width: 15%;" valign="top"> Amount of Points: </td> <td> <input style="position: relative; left: 16px;" type="text" size="15" name="pointamt" /> </td> <td> Do not put anything that is not a number into this box. </td> </tr> <tr> <td style="width: 15%;" valign="top"> Point Category: </td> <td colspan="10"> <select name="pointcat" style="position: relative; left: 16px;"> <option SELECTED value="">-------</option> <option>Class Work</option> <option>Class Exam</option> <option>Extra Work</option> <option>Contests</option> <option>Teacher\'s Assistant</option> <option>Negative Points</option> </select> </td> </tr> <tr> <td style="width: 15%;" valign="top"> Reason: </td> <td colspan="10"> <input style="position: relative; left: 16px;" name="pointreason" type="text" size="80" /> </td> </tr> <tr> <td> </td> <td colspan="10"> <input style="position: relative; left: 16px;" type="submit" value="Submit Points" /> </td> </tr> </table </form> '; } elseif (1==1) { $addpointspage = $accessdenied; } echo ' <!-- start content --> <div id="content"> <div class="post"> <div class="entry"> <p><strong>' . $addpointspage . '</p> <p class="links">' . $addpointslink . '</p> </div> </div> </div> <!-- end content --> <div style="clear: both;"> </div> </div> <!-- end page --> </div>'; echo $footer; ?> I am fairly new to PHP, so I would appreciate any help someone could give me; I am not too good with arrays and such, so this one has got me stumped. I have textfield for signature in my form, I m checking if the signature was sent ( if(!empty($_POST['signature'])) and if it's not empty I m putting it into the db. The problem is that, I have noticed a greek user has entered something in greek letters, and function could not deal with it and saved it as it is.( DB field supports greek charset ) I just want to allow english and german chars with special chars ( ",',< etc. ) , no other charset like greek. How can I do that? any function for this purpose ? $characterIDs = explode(',', $_POST['characterIDList']); After the explode I want to take all those values and do a select statement in a database table for any of the values that match any of the values inside that variable variable. Not sure how to do this since there is no limit to how may there could be. Okay I need some help. I want to check a MySQL DB and then if it says 0 then don't do anything if it says anything else echo out what's there. I have tried for about a hour now. Hello all, it's been a while! Good to be back. I am having trouble with a script I'm trying to modify to seach for domains with specific extensions. Now, I have never done any domain checking before and I'm a little bewildered. The script uses an array and checks the input against each extension using the array. Each line looks similar to: Code: [Select] '.com' => array('whois.crsnic.net','No match for'), What does the whois.crsnic.net mean? I assume it's a register/database of domains? I need to query a database for a starting time for a meeting, and if the start time is at 7pm, I need to allow access to a page from 6pm til 11pm. Not a problem. The problem lies when the ending time (4 hours after the start time) crosses over to a new day. Here's what I have: Code: [Select] <?php elseif ($row['meeting'] == "7:00pm") { $starthour = 18; $endhour = 23; } elseif ($row['meeting'] == "8:00pm") { $starthour = 19; $endhour = 0; } if ($thishour <= $endhour && $thishour >= $starthour) { include "meeting_ok.php"; } else { echo "Meeting room is unavailable at this time...."; } ?> The "0" for endhour is throwing things off. How should I best account for a new day? Thanks! Hey everyone.. I cleared the earlier doubt i have a new doubt in the same system.. <code> public function login($uname, $pass,$remember=false) { $result =$this->db->query("SELECT * FROM tbl_userauth"); $result->execute(); $resl=$result->fetchAll(PDO::FETCH_ASSOC); if ($resl[0]['username'] !=$uname || $resl[0]['password']!=$pass) { return $this->error("User not Found"); } else { $userID=$resl[0]['userid']; $_SESSION['userid']=$userID; $uname=$resl[0]['username']; $_SESSION['uname']=$uname; if(isset($_SESSION['userid'])) { header("location:dash.php"); } else { header("location:login.php"); } } </code> No this is my system actually i wanted to do session checking..Rite now when i am logging in the system i am able to log in but the same URL if i copy and paste in another browser i dont have to log in i am already logged in that's not rite Na?? I mean in another browser i should b logging in and then able to access in rite????What am i doing wrong???? PLease guide me through..Thank you.. I don't know precisely how to put it so i will give an example: suppose you have a search form with input fields for: -an age range, -a data range, -for the sex, -postal code as soon as the user would fill in one of these input fields, a query should be generated including a condition doing something with the inputted value. For example, the user fills in maxAge, the the query should say: SELECT * FROM table WHERE age >= maxAge; Filling more than one criterion then would do .= " AND criteria (condition) inputvalue " etc... My question comes to the part about: how to check if there is already a WHERE in the clause and how to put WHERE or AND for every criterion. Since doing like above, i won't be able to search for another criterion if i don't select maxAge first because then there would be no WHERE in the sql clause. Hopefully i've put it clear thanks in advance Can someone help me to get this code working... Code: [Select] public function getBowlContents(){ if is_null($this->contents) { return "The bowl is empty!"; } else { return "The bowl contains " . $this->contents . " soup!"; } TomTees Hello! Does anyone know an effective way to track inactive idlers in daily basis? So that it will count the amount of days no data has been posted to the table. E.g. User posts latest data and inserts timestamp 1282228120 which reads Thursday, August 19th 2010, 14:28:40 (GMT) The days for inactivity should output as 8 days because no data has been posted from 20th August to today - 28th August. Anyway I can achieve this? Any information is appreciated, thanks. Hey In my spare time, I am working on my PHP framework. Now, to help with development and quickly discover where I miss a type cast, I have adopted to check all parameters that are passed to a method using a function. For instance: public function __construct(&$target = null, $depth = 1){ $this->validateArguments( array(1 => 'int'), array(1 => $depth) ); And the code that triggers the exception: public function testPhpFreakType(){ $obj = 1; $p = new Xcms_DataStructures_Pointer($obj, "1"); } Code: [Select] 0: |--------------------------------------------------| 1: |--Exception: 4cfe2e86ca5970.22624423 - Full Trace | 2: | Tue, 07 Dec 2010 13:54:30 +0100 3: |-Class: 4: | Xcms_Exceptions_InvalidArgument 5: |-Message: 6: | Argument #1 of Xcms_DataStructures_Pointer:__construct() is no _null:int 7: | Stack offset: 3 8: | 9: |-Trace 10: | #0 D:\www\xcms_rev\core\exceptions\invalid.argument.helper.class.php(133): Xcms_Exceptions_InvalidArgumentHelper::factory(1, '_null:int', NULL, 2) 11: | #1 D:\www\xcms_rev\core\basic.class.php(80): Xcms_Exceptions_InvalidArgumentHelper::validateArguments(Array, Array, Array, 1) 12: | #2 D:\www\xcms_rev\core\data.structures\pointer.class.php(49): Xcms_Basic->validateArguments(Array, Array) 13: | #3 D:\www\xcms_rev\core\data.structures\pointer.test.php(73): Xcms_DataStructures_Pointer->__construct(1, '1') 14: | #4 [internal function]: Xcms_DataStructures_PointerTest->testPhpFreakType() 15: | #5 C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php(737): ReflectionMethod->invokeArgs(Object(Xcms_DataStructures_PointerTest), Array) 16: | #6 C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php(627): PHPUnit_Framework_TestCase->runTest() 17: | #7 C:\xampp\php\PEAR\PHPUnit\Framework\TestResult.php(629): PHPUnit_Framework_TestCase->runBare() 18: | #8 C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php(575): PHPUnit_Framework_TestResult->run(Object(Xcms_DataStructures_PointerTest)) 19: | #9 C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php(766): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult)) 20: | #10 C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php(742): PHPUnit_Framework_TestSuite->runTest(Object(Xcms_DataStructures_PointerTest), Object(PHPUnit_Framework_TestResult)) 21: | #11 D:\www\xcms_rev\core\testing\manager.class.php(83): PHPUnit_Framework_TestSuite->run() 22: | #12 D:\www\xcms_rev\core\testing\manager.class.php(56): Xcms_Testing_Manager->testClass(Object(ReflectionClass)) 23: | #13 D:\www\xcms_rev\cache\pkg\scripting\script_1.php(3): Xcms_Testing_Manager->run(Object(Xcms_Url_DefaultRequest)) 24: | #14 D:\www\xcms_rev\core\util.lib.php(340): include('D:\www\xcms_rev...') 25: | #15 D:\www\xcms_rev\core\packages\scripting\controllers\scripting.controller.php(66): Xcms_Util::sandboxedInclude('cache/pkg/scrip...', Array) 26: | #16 D:\www\xcms_rev\core\mvc\controllers\default.controller.php(210): Xcms_Packages_Scripting_Controllers_ScriptingController->execute(Object(Xcms_Packages_Scripting_Models_ScriptModel), Object(Xcms_Templating_Context)) 27: | #17 D:\www\xcms_rev\core\mvc\controllers\default.controller.php(170): Xcms_Mvc_Controllers_DefaultController->runScript(1, 0, Object(Xcms_Templating_Context)) 28: | #18 D:\www\xcms_rev\core\mvc\controllers\default.controller.php(132): Xcms_Mvc_Controllers_DefaultController->runScripts(0, 0, Array, Array, 1, 0) 29: | #19 D:\www\xcms_rev\index.php(15): Xcms_Mvc_Controllers_DefaultController->run() 30: | #20 {main} 31: |--------------------------------------------------| I think this speeds up my development quite a bit, because I can catch errors very early in the development process. I can give multipe possibilities of what is allowed for each parameter, not just a single possibility. Also, it is possible to register custom type/validity-checks on both global and local scope. One thing I do worry about, however, is the the performance. Of course, I could just make the funciton do nothing in production code, if it takes too much time, or I could write a script to remove all calls to that function. When I started learning python a while back, the concept to just code to interfaces instead of types seemed very intuitive and made my code much more flexible. Of course that is what I do with PHP as well, but I it's not entirely the same. So now, coming back at my PHP code and having introduced features of static languages such as type checking, I worry about whether that is the right approach. What are your thoughts on the matter? Scenario: each row contains an ID, title, description, price, and up to 5 images. There are not always 5 images stored in each row. The images are stored as a file path which is then pulled out of the DB and used to display an image via HTML. I need to do some sort of loop/check that looks at the contents of a particular row (actually all rows in this particular table) and then decide how many times to loop through the images to display them all correctly on the webpage. I could statically set a variable for each column but then it would have a space for an image but nothing would show. I really want this to be able to only load the images that are stored in the DB. Any help on how I can go about this? thanks -beemer |