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. Quote Link to comment Share on other sites More sharing options...
gergy008 Posted August 18, 2009 Author Share Posted August 18, 2009 Bump. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
jamesxg1 Posted August 18, 2009 Share Posted August 18, 2009 Cool dude, Good luck. James. Quote Link to comment 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); } } } Quote Link to comment 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... Quote Link to comment 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! Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.