Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7536527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:35:57+00:00 2026-05-30T06:35:57+00:00

Alright, I’m trying to make it so that someone can vote for a server

  • 0

Alright, I’m trying to make it so that someone can vote for a “server” every 24 hours, but currently, I’m stuck here:

    function vote1() {
    $pull = $_SERVER['REMOTE_ADDR'];
    $votersIp = "select votersIp from voters";
    $usersIp = $_SERVER['REMOTE_ADDR'];





    $fetch = mysql_query("SELECT * FROM voters WHERE votersIp = '".$_SERVER['REMOTE_ADDR']."'");



        while($rude = mysql_fetch_array($fetch)){  

    if($rude[votersIp] != $pull) {
    $zoot="INSERT INTO voters (votersIp, lastVoted) VALUES ('$usersIp', '0')";
    mysql_query($zoot) or die ( mysql_error() );
    echo 'Voters IP not in database'; //debugging
    }

    if($rude[votersIp] = $pull) {
     echo 'found ip'; //debugging
    }

}

So, if you can’t tell, I’m trying to make it so that everytime someone votes, it adds their IP address to the database. I know I’m doing something very basic wrong here, but I’m still learning.

I would appreciate it if you could post the fix, but also explain what I’m doing wrong, and any suggestions would be great as well.

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:35:58+00:00Added an answer on May 30, 2026 at 6:35 am

    There are several problems in your code.

    1. A close bracket } is missing, either for the while or for the function

    2. We don’t need to loop through all the voters table to find out if an IP is in the database or not. We can simply use a WHERE clause in the SQL command, like this: SELECT votersIp FROM voters WHERE votersIp = $userIp

    3. There are a lot of unnecessary variables with strange names.

    4. As a security measure, anything we will use as a part of a SQL command should be escaped, to avoid being vulnerable to some types of attacks.

    5. When array indexes are strings, they should be between quotes. So, $rude[votersIp] is wrong, while $rude['votersIp'] is correct. (Without quotes, PHP interprets it as a constant, instead of a string.)

    6. The $rude[votersIp] = $pull statement is a variable assignment. You should use the correct operator == to compare values: $rude[votersIp] == $pull

    7. Bad indentation makes the code harder to be understood for us, human readers. Good indentation is better.

    8. The while loop is done upon the results of the query which searchs for a specific IP. This means the first condition of the if inside it will NEVER be true (a different IP), so never the INSERT will run.

    Here is an improved version:

    function vote()
    {
        $ip = $_SERVER['REMOTE_ADDR'];
        $select = 'SELECT votersIp FROM voters WHERE votersIp = "' . mysql_real_escape_string($ip) . '"';
        $search = mysql_query($select);
        $voter = mysql_fetch_array($search);
    
        if (!empty($voter))
        {
            echo 'found ip'; //debugging
        }
        else
        {
            echo 'Voters IP not in database'; //debugging
            $insert = 'INSERT INTO voters (votersIp, lastVoted) VALUES ("' . mysql_real_escape_string($ip) . '", "0")';
            mysql_query($insert);
        }
    }
    

    Suggestion: you should read and study a good book about programming for beginners. As I can’t recommend a specific book for you, I suggest you ask for a book recommendation. A good book to learn how to program, for beginners.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, here we go! I am currently developing an iPhone app that will work
Alright so my question is, how can I make a program that basically executes
Alright, currently I have my SWF hitting a php file that will go and
Alright, I'm trying to read a comma delimited file and then put that into
Alright, after doing a ton of research and trying almost every managed CPP Redist
Alright, here's what I'm trying to do. I'm attempting to write a quick build
Alright, here is my problem i'm trying to solve. I have an index page
Alright, hoping someone can help. I've got a page used to search for employees.
Alright, I or someone I work with broke the syntax here somewhere, and I'm
Alright, so I've been trying to implement a simple binary search tree that uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.