mastercjb Posted May 12, 2009 Share Posted May 12, 2009 Say I would like to set up a shop... In my database I have money, and points... How would I set a code to take money out and put points in. Basically a store where you would spend "money" to buy "points". Money and points are both in the user part of the database... I cant for the life of me find how to write this code. Quote Link to comment https://forums.phpfreaks.com/topic/157758-how-would-i/ Share on other sites More sharing options...
Maq Posted May 12, 2009 Share Posted May 12, 2009 What do you have done so far? What kind of knowledge do you possess? Is there something specific you need help with or are you building this from scratch? Assuming you're going to be using PHP and MySQL, read this: PHP and MySQL. Quote Link to comment https://forums.phpfreaks.com/topic/157758-how-would-i/#findComment-832106 Share on other sites More sharing options...
mastercjb Posted May 12, 2009 Author Share Posted May 12, 2009 I'm a beginner to coding in php So far the only things I have set up is a shop to spend points to give you other things such as nerve for crimes, energy for training, and hitpoints. This is the code for the store page where they can use points to buy energy and nerve: <?php include 'header.php'; if ($_GET['spend'] == "nerve"){ if($user_class->points > 9) { $newpoints = $user_class->points - 10; $result = mysql_query("UPDATE `grpgusers` SET `nerve` = '".$user_class->maxnerve."', `points`='".$newpoints."' WHERE `id`='".$_SESSION['id']."'"); echo Message("You spent 10 points and refilled your nerve."); } else { echo Message("You don't have enough points, silly buns."); } } if ($_GET['spend'] == "energy"){ if($user_class->points > 9) { $newpoints = $user_class->points - 10; $result = mysql_query("UPDATE `grpgusers` SET `nerve` = '".$user_class->maxnerve."', `points`='".$newpoints."' WHERE `id`='".$_SESSION['id']."'"); echo Message("You spent 10 points and refilled your nerve."); } else { echo Message("You don't have enough points, silly buns."); } } ?> <tr><td class="contenthead">Point Shop</td></tr> <tr><td class="contentcontent"> Welcome to the Point Shop, here you can spend your points on various things.</td></tr> <tr><td class="contentcontent"> <table> <tr> <td><a href='spendpoints.php?spend=nerve'>Refill Nerve</a></td> <td> - 10 Points</td> </tr> <tr> <td><a href='spendpoints.php?spend=energy'>Refill Energy</a></td> <td> - 10 Points</td> </tr> </table> </td></tr> <?php include 'footer.php'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/157758-how-would-i/#findComment-832112 Share on other sites More sharing options...
PFMaBiSmAd Posted May 12, 2009 Share Posted May 12, 2009 I cant for the life of me find how to write this code.Writing code to perform a task is not a matter of finding how to write it. You define the problem, break it down into the steps necessary to accomplish the task, then write the code that implements each step. Your broad general question "How would I...." is not something that a programming help forum can answer because it would require a lot more than the few hundred words that would be possible in a typical reply. Do you have a specific question about some part of this, a specific problem with existing code, or a specific error that you need help with? These are the kind of things that a programming help forum can help you with. Quote Link to comment https://forums.phpfreaks.com/topic/157758-how-would-i/#findComment-832114 Share on other sites More sharing options...
mastercjb Posted May 12, 2009 Author Share Posted May 12, 2009 Ok, well do you think there would be a way to take this part of this code and turn it to take money instead of points, and then give that user points?? if ($_GET['spend'] == "nerve"){ if($user_class->points > 9) { $newpoints = $user_class->points - 10; $result = mysql_query("UPDATE `grpgusers` SET `nerve` = '".$user_class->maxnerve."', `points`='".$newpoints."' WHERE `id`='".$_SESSION['id']."'"); echo Message("You spent 10 points and refilled your nerve."); } else { echo Message("You don't have enough points, silly buns."); } } Quote Link to comment https://forums.phpfreaks.com/topic/157758-how-would-i/#findComment-832139 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.