gergy008 Posted August 18, 2009 Share Posted August 18, 2009 Ok. What I need is a script that will give a user a certain amount of cash everyday. (If they arn't logged on they don't get it.)-- Only do this if it makes it easier. So. How do I go about it? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/170758-solved-help-giving-a-user-login-bonus-cash-everyday/ Share on other sites More sharing options...
gergy008 Posted August 18, 2009 Author Share Posted August 18, 2009 Bump. Link to comment https://forums.phpfreaks.com/topic/170758-solved-help-giving-a-user-login-bonus-cash-everyday/#findComment-900569 Share on other sites More sharing options...
jamesxg1 Posted August 18, 2009 Share Posted August 18, 2009 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 https://forums.phpfreaks.com/topic/170758-solved-help-giving-a-user-login-bonus-cash-everyday/#findComment-900576 Share on other sites More sharing options...
gergy008 Posted August 18, 2009 Author Share Posted August 18, 2009 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 https://forums.phpfreaks.com/topic/170758-solved-help-giving-a-user-login-bonus-cash-everyday/#findComment-900579 Share on other sites More sharing options...
jamesxg1 Posted August 18, 2009 Share Posted August 18, 2009 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 https://forums.phpfreaks.com/topic/170758-solved-help-giving-a-user-login-bonus-cash-everyday/#findComment-900582 Share on other sites More sharing options...
jamesxg1 Posted August 18, 2009 Share Posted August 18, 2009 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 https://forums.phpfreaks.com/topic/170758-solved-help-giving-a-user-login-bonus-cash-everyday/#findComment-900583 Share on other sites More sharing options...
gergy008 Posted August 18, 2009 Author Share Posted August 18, 2009 I decided to turn it into a function, Then call the function after the sessions have been set so I can quickly grab it afterwards. Hope fully it should work, I'll keeps you updated Link to comment https://forums.phpfreaks.com/topic/170758-solved-help-giving-a-user-login-bonus-cash-everyday/#findComment-900587 Share on other sites More sharing options...
jamesxg1 Posted August 18, 2009 Share Posted August 18, 2009 Cool dude, Good luck. James. Link to comment https://forums.phpfreaks.com/topic/170758-solved-help-giving-a-user-login-bonus-cash-everyday/#findComment-900590 Share on other sites More sharing options...
gergy008 Posted August 18, 2009 Author Share Posted August 18, 2009 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 https://forums.phpfreaks.com/topic/170758-solved-help-giving-a-user-login-bonus-cash-everyday/#findComment-900591 Share on other sites More sharing options...
gergy008 Posted August 18, 2009 Author Share Posted August 18, 2009 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 https://forums.phpfreaks.com/topic/170758-solved-help-giving-a-user-login-bonus-cash-everyday/#findComment-900593 Share on other sites More sharing options...
gergy008 Posted August 18, 2009 Author Share Posted August 18, 2009 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 https://forums.phpfreaks.com/topic/170758-solved-help-giving-a-user-login-bonus-cash-everyday/#findComment-900598 Share on other sites More sharing options...
gergy008 Posted August 18, 2009 Author Share Posted August 18, 2009 UPDATE: Got it working! Thanks James for helping! Link to comment https://forums.phpfreaks.com/topic/170758-solved-help-giving-a-user-login-bonus-cash-everyday/#findComment-900609 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.