Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/157758-how-would-i/
Share on other sites

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';
?>

Link to comment
https://forums.phpfreaks.com/topic/157758-how-would-i/#findComment-832112
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/157758-how-would-i/#findComment-832114
Share on other sites

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.");
}
}

Link to comment
https://forums.phpfreaks.com/topic/157758-how-would-i/#findComment-832139
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.