Jump to content

[SOLVED] Help giving a user login bonus cash everyday?


gergy008

Recommended Posts

Ok well this is how i would go about it,

 

--MYSQL ROWS--

 

username, password, logdate, balance.

 

then upon login i would update the 'logdate' to the date of login and then add the amount you are going to give them to balance,

 

and i would go about 'one time login' like so

 

if($row['logdate'] == date("Y-m-d")) {

} else {

$amount = $row['amount'];
$amount++

mysql_query("UPDATE `members` SET logdate = 'date("Y-m-D")', amount = '$amount'");
}

 

Get what i mean ?,

 

James.

Link to comment
Share on other sites

Ok well this is how i would go about it,

 

--MYSQL ROWS--

 

username, password, logdate, balance.

 

then upon login i would update the 'logdate' to the date of login and then add the amount you are going to give them to balance,

 

and i would go about 'one time login' like so

 

if($row['logdate'] == date("Y-m-d")) {

} else {

$amount = $row['amount'];
$amount++

mysql_query("UPDATE `members` SET logdate = 'date("Y-m-D")', amount = '$amount'");
}

 

Get what i mean ?,

 

James.

 

Thanks for replying. I kinda get what you mean.

 

Only trouble is, I'm new to SQL Rows... I might need to find a good tutorial on them.

Link to comment
Share on other sites

Heres a simple sql dump read it carefully and modify what i have in caps.

 

CREATE TABLE IF NOT EXISTS `!!!YOUR TABLE NAME HERE!!!` (
  `id` int(11) NOT NULL,
  `username` varchar(32) NOT NULL,
  `firstname` varchar(100) NOT NULL,
  `lastname` varchar(100) NOT NULL,
  `email` varchar(300) NOT NULL,
  `amount` int(11) NOT NULL,
  `lastlogin`  date NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

 

Ok, SQL dump done, now use the code i gave you previous but modify it abit to your needs :),

 

James.

Link to comment
Share on other sites

Use a code that would work in a similar way to this one,

 

while($row = mysql_fetch_array($con)) {

if($row['lastlogin'] == date("Y-m-d")) {

header('Location: user_home.php');

} else {

$amount = $row['amount'];
$amount+10;

mysql_query("UPDATE `members` SET logdate = 'date("Y-m-D")', amount = '$amount'");
header('Location: user_home.php');

  }
}

 

James.

Link to comment
Share on other sites

Cool dude, Good luck.

 

James.

 

Would this function work?Or did I mess up the rows and stuff?

 

$link is the database connection.

 

function update_cash()
{
global $link;

$sql="SELECT * FROM users WHERE login='".$_SESSION["login"]."'";
$con = mysql_query($sql, $link);
while($row = mysql_fetch_array($con)){
	if($row['lastlogin'] != date("Y-m-d")){
		$amount = $row['cash'];
		$amount+10;

		mysql_query("UPDATE `users` SET logdate = '".date("Y-m-D")."', cash = '$amount'", $link);
	}
}
}

Link to comment
Share on other sites

I just spotted an error in the last SQL code. Hopefully it will work now!

 

EDIT: Big error... Here is my function:

 

//function to update players cash
function update_cash()
{
global $link;

$sql="SELECT * FROM users WHERE login='".$_SESSION["login"]."'";
$con = mysql_query($sql, $link) or die("Failed to select. Error if any: ".mysql_error());
while($row = mysql_fetch_array($con)){
	if($row['lastlogin'] == date("Y-m-d")){
		return "No login bonus. Come again tomorrow!";
	} else {
		$amount = $row['cash'];
		$amount+10;

		mysql_query("UPDATE `users` SET lastlogin = '".date("Y-m-d")."', cash = '$amount'", $link) or die("Failed to update. Error if any: ".mysql_error());
		return "Login bonus given! Thanks for visiting!";
	}
}
}

 

It is setting everyones cash to the first amount without adding anything, And setting EVERYONE in the tables lastlogin date to mine...

Link to comment
Share on other sites

I just spotted an error in the last SQL code. Hopefully it will work now!

 

EDIT: Big error... Here is my function:

 

//function to update players cash
function update_cash()
{
global $link;

$sql="SELECT * FROM users WHERE login='".$_SESSION["login"]."'";
$con = mysql_query($sql, $link) or die("Failed to select. Error if any: ".mysql_error());
while($row = mysql_fetch_array($con)){
	if($row['lastlogin'] == date("Y-m-d")){
		return "No login bonus. Come again tomorrow!";
	} else {
		$amount = $row['cash'];
		$amount+10;

		mysql_query("UPDATE `users` SET lastlogin = '".date("Y-m-d")."', cash = '$amount'", $link) or die("Failed to update. Error if any: ".mysql_error());
		return "Login bonus given! Thanks for visiting!";
	}
}
}

 

It is setting everyones cash to the first amount without adding anything, And setting EVERYONE in the tables lastlogin date to mine...

 

Fixed that bit. I fogot the to put WHERE in.

 

Ok now I have another problem.

 

It won't update the cash!

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.