anyone here good at php coding ? if yesh can you plz help me with this simple coding. create a "daily Points" page that each member gets 200 points every day by clicking the button. every 24 hours no cookies. im not that good with a php but here is exp that i found. <?php //connection to the database goes here $query11 = mysql_query("SELECT * FROM users WHERE points = '$points' "); $points11 = mysql_fetch_array($query11); $datepoint = date("j"); if($points11[point_24] == "$datepoint") { echo"You have already collected your daily Points. Please collect them in another 24 hours."; echo("</td> </tr> </table> </div> </fieldset>"); include ("http://mydomain.com/footer.html"); exit; } else { $query = mysql_query("UPDATE membership SET points_24 = '$datepoint' WHERE name= '$member'"); $point = $points11[points] + 200; $addpoint = mysql_query("UPDATE membership SET points = '$point' WHERE name = '$member'"); $query111 = mysql_query("SELECT * FROM membership WHERE name = '$member' "); $points111 = mysql_fetch_array($query111); echo "You have now collected your daily Points. You have <b>$points111[points]</b> Points.; } ?> PHP:
You have no functionality to accurately update your table to include data on when the row was last updated. Consider using epoch and checking if the button is clicked >86400 seconds since last table update: 'j' will only provide day number within the month, 1 to 31. Further information is available at php.net/manual/en/function.date.php Consider thinking it through, logically, before writing a single line of code. R
Hello, I am posting a small code of how to do it below. Please check it. If you cannot understand it then let me know. I have checked for 20 sec instead of 24 hrs so that it becomes easier for you to check if its working or not. DB Structure: 1 id int(11) AUTO_INCREMENT 2 user_id int(11) 3 last_click_timestamp int(11) --------------------------------------------- <?php if(isset($_POST[sub])) //checking if the GO button is clicked { mysql_connect("localhost","root",""); //mysql_connection $sql="select * from test.test1 where user_id=1"; $res=mysql_query($sql); $row=mysql_fetch_array($res); if($row[last_click_timestamp]+20 < time()) //checking if the button was clicked 20 sec before the present time { $sql="update test.test1 set `last_click_timestamp`=".time()." where user_id=1"; //if yes, then setting the last_click_timestamp to the present time. mysql_query($sql); header("location:test.php?points=added"); //redirecting to the same page with a query string } else header("location:test.php?points=not_added"); } if($_GET[points]=="added") echo "200 points added to your account. Visit again in 20 secs"; if($_GET[points]=="not_added") echo "you have already claimed you points in last 20 secs, try after another 20 secs"; ?> <form method=POST> <input type=submit value=" GO " name="sub"> </form> -------------------------------------------------------------------------- Hope I was able to help you. Waiting for a reply! Thanks.
im getting 1 error after i change the codes below, also it doesn't says what amount points should update/insert to database Notice: Use of undefined constant coins - assumed 'coins' in ..\get.php on line 16 Notice: Undefined index: coins in ..\get.php on line 16 it gets the link ..\get.php?points=added but points are not added the errors are in: line 16. if($_GET[coins]=="added"){ <?php if(isset($_POST['sub'])) //checking if the GO button is clicked { mysql_connect("localhost","test",""); //mysql_connection $sql="select * from users WHERE coins id=$id"; $res=mysql_query($sql); $row=mysql_fetch_array($res); if($row[last_click_timestamp]+20 < time()) //checking if the button was clicked 20 sec before the present time { $sql="update users set `last_click_timestamp`=".time()." where id=$id"; //if yes, then setting the last_click_timestamp to the present time. mysql_query($sql); header("location:settings.php?points=added"); //redirecting to the same page with a query string } else header("location:settings.php?points=not_added"); } if($_GET[coins]=="added"){ echo "200 points added to your account. Visit again in 20 secs"; if($_GET[coins]=="not_added") echo "you have already claimed you points in last 20 secs, try after another 20 secs"; } ?> PHP:
Sorry, but I did not post the above according to your script. I just tried to explain you the logic of how to do it. You need to use the logic according to the way your script requires. If you want me to fix this then we need to have a chat. And yes, you are seeing the NOTICE/Warning as error_reporting is not disabled in your php.ini. You can simpley use error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE); at the top of the page. Thanks.
hey, i made another code, but this one is changing the points/coins from database tables, exp: if the users have 100 points/coins and the update is 50 points/coins, when the users clicks on the button it changes their points/coins to 50 [not 150], the script is updating the users points not adding it, how do i fix that skype: walidsu2 <?php include 'config.php'; if(isset($data)) { foreach($_POST as $key => $value) { $posts[$key] = filter($value); } if(isset($posts["coins"])) { $checkForUser = mysql_query("SELECT * FROM `test` WHERE `coins`='{$posts['coins']}'"); $checkForUserRows = mysql_num_rows($checkForUser); mysql_query("UPDATE `test` SET `coins` = '{$posts['coins']}' where `id`='{$data->id}'"); $success = "Your settings has been updated!"; } ?> <form method="post"> Coins<br/> <input type="text" name="coins" value="<?php echo $data->coins; ?>"><br/> <input style="" type="submit" value="Update"/><br/><br/><br/><br/> </form> PHP:
You should add [COLOR=#990000]mysql_query[/COLOR][COLOR=#009900][FONT=monospace]([/FONT][/COLOR][COLOR=#0000FF][FONT=monospace]"UPDATE `test` SET `coins` = coins + [COLOR=#006699][B]{$posts['coins']}[/B][/COLOR] where `id`='[COLOR=#006699][B]{$data->id}[/B][/COLOR]'"[/FONT][/COLOR][COLOR=#009900][FONT=monospace])[/FONT][/COLOR][COLOR=#339933][FONT=monospace];[/FONT][/COLOR] Code (markup): instead of [COLOR=#990000]mysql_query[/COLOR][COLOR=#009900][FONT=monospace]([/FONT][/COLOR][COLOR=#0000FF][FONT=monospace]"UPDATE `test` SET `coins` = '[COLOR=#006699][B]{$posts['coins']}[/B][/COLOR]' where `id`='[COLOR=#006699][B]{$data->id}[/B][/COLOR]'"[/FONT][/COLOR][COLOR=#009900][FONT=monospace])[/FONT][/COLOR][COLOR=#339933][FONT=monospace];[/FONT][/COLOR] Code (markup): But anyway, I suggest you to not use this code because it's not secure. For example, someone can send a request with any $_POST['coins'] value, so he will have as many coins as he wants.