Leverkusen Posted January 28, 2014 Share Posted January 28, 2014 http://paste2.org/B62gO0Fe this is my php code for posts currently its unlimited, i want to limit to 1 post per day. the user must wait until 00:00 to post again Quote Link to comment Share on other sites More sharing options...
kicken Posted January 28, 2014 Share Posted January 28, 2014 Before you do your INSERT query, run a SELECT to see if the user has already posted an item that day. If so then don't do the INSERT and show an error message. Quote Link to comment Share on other sites More sharing options...
Leverkusen Posted January 29, 2014 Author Share Posted January 29, 2014 im confused how would it look like,date and curdate are confusing me $tim1 and $tim2 with $tip $kvota and $link is the full post its not a single post http://prntscr.com/2ns1d0 Quote Link to comment Share on other sites More sharing options...
Leverkusen Posted January 31, 2014 Author Share Posted January 31, 2014 bump Quote Link to comment Share on other sites More sharing options...
Leverkusen Posted January 31, 2014 Author Share Posted January 31, 2014 let me explain again, with this script http://paste2.org/B62gO0Fe i want to limit posts for everyday so i can choose can they put 1,2 or >2 posts per day so anytime i want to edit this script i can change the post limit Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 31, 2014 Share Posted January 31, 2014 There were some things in an inefficinet order, so I made other changes as well <?php $postLimit = 2; // upis para if($_POST['tim1']!="" and $_POST['tim2']!="" and $_POST['tip']!="" and $_POST['kvota']!="" and $_POST['link']!="") { $ip = $_SERVER['REMOTE_ADDR']; $tim1 = str_ireplace(array("\"", "'", ""),"", $_POST['tim1']); $tim2 = str_ireplace(array("\"", "'", ""),"", $_POST['tim2']); $tim1 = ucwords(strtolower($tim1)); $tim2 = ucwords(strtolower($tim2)); $tip = str_ireplace(array("\"", "'",""),"", $_POST['tip']); $kvota = str_ireplace(array(","), ".",$_POST['kvota']); $link = str_ireplace(" ", "", $_POST['link']); $prvoslovo = str_ireplace("http://www.flashscore.com/","#", $link); $linkDozvola = ($prvoslovo[0]=="#"); if(!$linkDozvola) { echo "alert('Vas link je neispravan. Link utakmice kopirajte sa www.flashscore.com .')"; } elseif($kvota99.99) { echo "alert('Kvota vam nije u opsegu od 1.01 do 99.99 .')"; } else { $racun = $_SESSION['liga_user_id']; $query = "SELECT cnr.klikovi, COUNT(cnr.id) AS post_count FROM clanovi_njihovi_racuni AS cnr LEFT JOIN clanovi_njihovi_parovi AS cnp ON cnr.id = cnp.racun AND cnp.datum=curdate() WHERE cnr.id='$racun' GROUP BY cnr.id"; $result = mysql_query($query); $row = mysql_result($result); $klikovi = $row['klikovi']; $postCount = $row['post_count']; if($klikovi<3) { echo "alert('Nemate dovoljan broj klikova za unos para(minimum je 3 klika po paru).')"; } elseif($postCount >= $postLimit) { //Limit met echo "Upoznala si maksimalno post count za danas"; } else { $query = "INSERT INTO clanovi_njihovi_parovi SET racun='$racun', ip='$ip', datum=curdate(), vrijeme=curtime(), tim1='$tim1', tim2='$tim2', tip='$tip', kvota='$kvota',link='$link';" $result = mysql_query($query); $query = "UPDATE clanovi_njihovi_racuni SET klikovi = klikovi-0 WHERE id='$racun'"; $result = mysql_query($query); echo "alert('Vas par je prihvacen')"; } } } ?> Quote Link to comment Share on other sites More sharing options...
Leverkusen Posted February 1, 2014 Author Share Posted February 1, 2014 (edited) <?php $postLimit = 2; // upis para if($_POST['tim1']!="" and $_POST['tim2']!="" and $_POST['tip']!="" and $_POST['kvota']!="" and $_POST['link']!="") { $ip = $_SERVER['REMOTE_ADDR']; $tim1 = str_ireplace(array("\"", "'", ""),"", $_POST['tim1']); $tim2 = str_ireplace(array("\"", "'", ""),"", $_POST['tim2']); $tim1 = ucwords(strtolower($tim1)); $tim2 = ucwords(strtolower($tim2)); $tip = str_ireplace(array("\"", "'",""),"", $_POST['tip']); $kvota = str_ireplace(array(","), ".",$_POST['kvota']); $link = str_ireplace(" ", "", $_POST['link']); $prvoslovo = str_ireplace("http://www.flashscore.com/","#", $link); $linkDozvola = ($prvoslovo[0]=="#"); if(!$linkDozvola) { echo "alert('Vas link je neispravan. Link utakmice kopirajte sa www.flashscore.com .')"; } else if($kvota<1.01and $kvota>99.99) { echo "alert('Kvota vam nije u opsegu od 1.01 do 99.99 .')"; } else { $racun = $_SESSION['liga_user_id']; $query = "SELECT cnr.klikovi, COUNT(cnr.id) AS post_count FROM clanovi_njihovi_racuni AS cnr LEFT JOIN clanovi_njihovi_parovi AS cnp ON cnr.id = cnp.racun AND cnp.datum=curdate() WHERE cnr.id='$racun' GROUP BY cnr.id"; $result = mysql_query($query); $row = mysql_result($result); $klikovi = $row['klikovi']; $postCount = $row['post_count']; if($klikovi<3) { echo "alert('Nemate dovoljan broj klikova za unos para(minimum je 3 klika po paru).')"; } elseif($postCount >= $postLimit) { //Limit met echo "Upoznala si maksimalno post count za danas"; } else { $query = "INSERT INTO clanovi_njihovi_parovi SET racun='$racun', ip='$ip', datum=curdate(), vrijeme=curtime(), tim1='$tim1', tim2='$tim2', tip='$tip', kvota='$kvota',link='$link';" $result = mysql_query($query); $query = "UPDATE clanovi_njihovi_racuni SET klikovi = klikovi-0 WHERE id='$racun'"; $result = mysql_query($query); echo "alert('Vas par je prihvacen')"; } } } ?> there is error row number 56 unexpected T_VARIABLE $result = mysql_query($query); is 56 and should i create post_count on my table? Edited February 1, 2014 by Leverkusen Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 1, 2014 Share Posted February 1, 2014 there is error row number 56 unexpected T_VARIABLE $result = mysql_query($query); is 56 The line above it is missing a semi-colon at the end and should i create post_count on my table? No, the query is JOINing the post table (clanovi_njihovi_parovi) with the user(?) table (clanovi_njihovi_racuni). But, it only JOINs the post records that have a date of today. It then GROUPS the records and dynamically assigns a value to the variable post_count. Quote Link to comment Share on other sites More sharing options...
Leverkusen Posted February 1, 2014 Author Share Posted February 1, 2014 hmm its says that i dont have enough clicks but i actually have.. <?php $postLimit = 2; // upis para if($_POST['tim1']!="" and $_POST['tim2']!="" and $_POST['tip']!="" and $_POST['kvota']!="" and $_POST['link']!="") { $ip = $_SERVER['REMOTE_ADDR']; $tim1 = str_ireplace(array("\"", "'", ""),"", $_POST['tim1']); $tim2 = str_ireplace(array("\"", "'", ""),"", $_POST['tim2']); $tim1 = ucwords(strtolower($tim1)); $tim2 = ucwords(strtolower($tim2)); $tip = str_ireplace(array("\"", "'",""),"", $_POST['tip']); $kvota = str_ireplace(array(","), ".",$_POST['kvota']); $link = str_ireplace(" ", "", $_POST['link']); $prvoslovo = str_ireplace("http://www.flashscore.com/","#", $link); $linkDozvola = ($prvoslovo[0]=="#"); if(!$linkDozvola) { echo "alert('Vas link je neispravan. Link utakmice kopirajte sa www.flashscore.com .')"; } else if($kvota<1.01and $kvota>99.99) { echo "alert('Kvota vam nije u opsegu od 1.01 do 99.99 .')"; } else { $racun = $_SESSION['liga_user_id']; $query = "SELECT cnr.klikovi, COUNT(cnr.id) AS post_count FROM clanovi_njihovi_racuni AS cnr LEFT JOIN clanovi_njihovi_parovi AS cnp ON cnr.id = cnp.racun AND cnp.datum=curdate() WHERE cnr.id='$racun' GROUP BY cnr.id"; $result = mysql_query($query); $row = mysql_result($result); $klikovi = $row['klikovi']; $postCount = $row['post_count']; if($klikovi<3) { echo "<script>alert('Nemate dovoljan broj klikova za unos para(minimum je 3 klika po paru).')</script>"; } elseif($postCount >= $postLimit) { //Limit met echo "Upoznala si maksimalno post count za danas"; } else { $query = "INSERT INTO clanovi_njihovi_parovi SET racun='$racun', ip='$ip', datum=curdate(), vrijeme=curtime(), tim1='$tim1', tim2='$tim2', tip='$tip', kvota='$kvota',link='$link'"; $result = mysql_query($query); $query = "UPDATE clanovi_njihovi_racuni SET klikovi = klikovi-0 WHERE id='$racun'"; $result = mysql_query($query); echo "alert('Vas par je prihvacen')"; } } } ?> Quote Link to comment Share on other sites More sharing options...
Leverkusen Posted February 3, 2014 Author Share Posted February 3, 2014 bump Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 3, 2014 Share Posted February 3, 2014 Why do you assume you have enough clicks? When you encounter a problem such as this a simple TEST should tell you the problem. I made a lot of changes, so I'm not guaranteeing that there were no errors. But, this should be very simple to debug. I'm not sure which condition is the check that you think is working incorrectly. I don't speak Bosnian and when I use a translator none of the message refer to 'clicks'. But, for whichever one you think is working incorrectly, just look at the condition check. Then test the values that are used for that condition check. If they don't look right, then go back to where they are defined to determine why they are not correct. Quote Link to comment Share on other sites More sharing options...
Leverkusen Posted February 4, 2014 Author Share Posted February 4, 2014 its Serbian actually this is the problem if($klikovi<3) { echo "<script>alert('Nemate dovoljan broj klikova za unos para(minimum je 3 klika po paru).')</script>"; } I have 3 clicks but this message is always showed when i want to post... and when i put <0 then nothing happens, no post maybe this query is not good enough $query = "SELECT cnr.klikovi, COUNT(cnr.id) AS post_count FROM clanovi_njihovi_racuni AS cnr LEFT JOIN clanovi_njihovi_parovi AS cnp ON cnr.id = cnp.racun AND cnp.datum=curdate() WHERE cnr.id='$racun' GROUP BY cnr.id"; Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted February 4, 2014 Share Posted February 4, 2014 Yeap, it's a Serbian language. There is no Bosnian or Macedonian languages So, what result you're getting running the query via phpMyAdmin, MySQL Workbench or other visual sql tool for mysql? Quote Link to comment Share on other sites More sharing options...
Leverkusen Posted February 4, 2014 Author Share Posted February 4, 2014 MySQL said: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<?php$postLimit = 2' at line 1 There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem ERROR: Unknown Punctuation String @ 1STR: <?SQL: <?php$postLimit = 2;<?php$postLimit = 2;<?php Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 4, 2014 Share Posted February 4, 2014 It looks as if there is PHP code getting into the query. The only way that I see that happening is with the variable $racun, which is defined as $_SESSION['liga_user_id']. Change the query execution to this: $result = mysql_query($query) or die("Query: {$query}<br>Error: " . mysql_error()); Then run the page and post the results. Quote Link to comment Share on other sites More sharing options...
Leverkusen Posted February 4, 2014 Author Share Posted February 4, 2014 hmm nothing happens, only <script>alert('Nemate dovoljan broj klikova za unos para(minimum je 3 klika po paru).')</script> appears, its still saying that i dont have enough click for post, no mysql errors Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted February 4, 2014 Share Posted February 4, 2014 (edited) Open up your GUI sql tool and run your sql code without any php itself. Example: SELECT cnr.klikovi, COUNT(cnr.id) AS post_count FROM clanovi_njihovi_racuni AS cnr LEFT JOIN clanovi_njihovi_parovi AS cnp ON cnr.id = cnp.racun AND cnp.datum=curdate() WHERE cnr.id='$racun' GROUP BY cnr.id EDIT: Replace '$racun' variable with an integer static value like 1, 2 or whatever you're expecting to be. Edited February 4, 2014 by jazzman1 Quote Link to comment Share on other sites More sharing options...
Leverkusen Posted February 5, 2014 Author Share Posted February 5, 2014 its empty result zero rows Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted February 5, 2014 Share Posted February 5, 2014 Can I see the results of DESCRIBE clanovi_njihovi_racuni; and DESCRIBE clanovi_njihovi_parovi; SELECT * from clanovi_njihovi_racuni where id = 1 Assuming the "id" with value 1 exists in this column. Quote Link to comment Share on other sites More sharing options...
Leverkusen Posted February 5, 2014 Author Share Posted February 5, 2014 (edited) http://prntscr.com/2pm2p7 http://prntscr.com/2pm2t6 http://prntscr.com/2pm355 Edited February 5, 2014 by Leverkusen Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted February 5, 2014 Share Posted February 5, 2014 (edited) What happens with the last select statement? Is there an id = 1? Post the result of select * from clanovi_njihovi_racuni where 1; Edited February 5, 2014 by jazzman1 Quote Link to comment Share on other sites More sharing options...
Leverkusen Posted February 5, 2014 Author Share Posted February 5, 2014 yea it is a registered user with username password and other http://prntscr.com/2pq5qr Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 5, 2014 Share Posted February 5, 2014 (edited) We are really working in the blind here. If something doesn't work please try to provide relevant information to help us help you. The screenshot you just linked to provides absolutely no useful information. It only tells us that there are records in the clanovi_njihovi_racuni table. It doesn't tell us if there are at least three records in the clanovi_njihovi_parovi table associated with the record in the clanovi_njihovi_racuni table that you are using in your script. Not to be rude, but you do realize that the query will only count posts for the current day, right? Even if the user has had 1,000 posts in the past, the count is only for the posts that they made today. That was your logic, so I had left it in. Run tthis query and show us the results - not the message stating the number of results: SELECT cnr.id, cnr.klikovi, COUNT(cnr.id) AS total_count, SUM(cnp.datum=curdate()) AS today_count FROM clanovi_njihovi_racuni AS cnr LEFT JOIN clanovi_njihovi_parovi AS cnp ON cnr.id = cnp.racun GROUP BY cnr.id Only the records for id's where the result for today_count is 3 or greater will make the condition if($klikovi<3) false. Edited February 5, 2014 by Psycho 1 Quote Link to comment Share on other sites More sharing options...
Leverkusen Posted February 5, 2014 Author Share Posted February 5, 2014 (edited) http://prntscr.com/2prdl4 Edited February 5, 2014 by Leverkusen Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted February 6, 2014 Share Posted February 6, 2014 (edited) Ok, step by step, are you done with that? currently its unlimited, i want to limit to 1 post per day. the user must wait until 00:00 to post again P.S If your answer is yes, show us the script. Edited February 6, 2014 by jazzman1 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.