Jump to content

How to add numbers from form with database numbers? S:


adamjones

Recommended Posts

Hi. I have a simple form with a username and amount field (This is to award a user coins). The info is then posted to this script, but I'm not sure how I would add the number from the form onto the amount of coins they already have (ie. They are awarded 50 coins, and already have 100 in the database, this should then be changed to 150)

 

This is my code so far;

<?php

session_start();
if(!session_is_registered(hh374747838807479736408649630860846496782)) {
header("location:./");
exit;
}
if(!session_is_registered(username)) {
header("location:./");
exit;
}
require_once('config.php');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
	die('Failed to connect to server: ' . mysql_error());
}
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
	die("Unable to select database");
}

function clean($str) {
	$str = @trim($str);
	if(get_magic_quotes_gpc()) {
		$str = stripslashes($str);
	}
	return mysql_real_escape_string($str);
}

$qry="SELECT * FROM fuse_rights WHERE username='".$_SESSION['username']."'";
$result=mysql_query($qry);

if($result) {
	if(mysql_num_rows($result) == 1) {

		$checks = mysql_fetch_assoc($result);
		$hk = $checks['housekeeping'];
		$comp = $checks['competitions'];
		$news = $checks['news'];
		$events = $checks['events'];
		$twitter = $checks['twitter'];
		$forum = $checks['forum_admin'];
		$pages = $checks['pages'];
		$users = $checks['users'];
		$settings = $checks['settings'];
		$bans = $checks['bans'];			
		}
		}

if(isset($_SESSION['username']) && $hk == 0)
{ $errflag = true;
	$errmsg_arr[] = 'You do not have access to the Intra.';
	if($errflag) {
	$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
	session_write_close();
	header("location: ./error");
	exit;
}
}
if(isset($_SESSION['username']) && $users == 0)
{ header("location: ./dash");
exit;
}
$username = clean($_POST['username']);
$amount = clean($_POST['amount']);

if($username == '') {
	$errmsg_arr[] = '<div id="message-error" class="message message-error">
							<div class="image">
								<img src="resources/images/icons/error.png" alt="Error" height="32" />
							</div>
							<div class="text">
								<h6>Error</h6>
								<span>Please choose a user.</span>
							</div>
							<div class="dismiss">
								<a href="#message-error"></a>
							</div>
						</div>';
	$errflag = true;
}

if($amount == '') {
	$errmsg_arr[] = '<div id="message-error" class="message message-error">
							<div class="image">
								<img src="resources/images/icons/error.png" alt="Error" height="32" />
							</div>
							<div class="text">
								<h6>Error</h6>
								<span>Please enter an amount.</span>
							</div>
							<div class="dismiss">
								<a href="#message-error"></a>
							</div>
						</div>';
	$errflag = true;
}

if($errflag) {
	$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
	header("location: ./give_coins");
	exit();

}

$sql="SELECT * FROM coins WHERE (username='$username')";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);

$currentamount = $rows['coins'];

// How to add the 
// $currentamount onto 
//the current user's coins? :S

$sql="UPDATE coins SET coins='' WHERE (username='$username')";
$result=mysql_query($sql);

if($result){

$errflag = true;
	$errmsg_arr[] = '<div id="message-success" class="message message-success">
							<div class="image">
								<img src="resources/images/icons/success.png" alt="Success" height="32" />
							</div>
							<div class="text">
								<h6>Success</h6>
								<span>Added Coins.</span>
							</div>
							<div class="dismiss">
								<a href="#message-success"></a>
							</div>
						</div>';
	if($errflag) {
	$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
	session_write_close();
	header("location: ./edit_user?username=".$username."#box-coins");
}
}
?>

 

Any ideas?

Thank you!

Link to comment
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.