Jump to content

Limit to 1 post per day


Leverkusen

Recommended Posts

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')";
}
}
}

?>
Link to comment
Share on other sites

<?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 by Leverkusen
Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

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')";
        }
    }
}

?>
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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";
Link to comment
Share on other sites

MySQL said: dot.gif

#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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by jazzman1
Link to comment
Share on other sites

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 by Psycho
  • Like 1
Link to comment
Share on other sites

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 by jazzman1
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.