/    Sign up×
Community /Pin to ProfileBookmark

Submit Button to Deduct Credits When Logged In

My goal is to have info from a database echoed out and then available to be purchased by pressing a button. The info is being echoed properly but when the button is pressed it adds the $cost variable up for all of the qualifying variable vs the single one that it should be attached to… hopefully that makes sense.

Also, when I refresh the page the “credits” are deducted from the users account, I was under the impression that a button would stop this from happening…

[code=php]

$get = mysql_query(“SELECT * FROM ac WHERE state=’Alabama’ ORDER BY datetime DESC LIMIT $start, $per_page”);

while ($row = mysql_fetch_assoc($get))
{

$cost = $row[‘cost’];

$submit = $_POST[‘submit’];

if ($submit)
{
if(loggedin())
{
if ($credits<$cost)
{
$option2 = “../../buycredits.php”;
}
else
{
$option2 = “ac_alabama.php”;
$get;
$deduct = mysql_query(“UPDATE users SET credits=credits-$cost WHERE username=’$username'”);
}
}
else
$option2 = “home.html”;
}

echo”
<form action=’$option2′ method=’POST’>
<input type=’submit’ name=’submit’ value=’Purchase’>
</form>
“;
}

[/code]

Any and all help is greatly appreciated!

Thanks in advance.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@jsnewbie1authorJul 05.2011 — Nevermind! I figured out what the issue was. Thanks anyways.
×

Success!

Help @jsnewbie1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...