Results 1 to 5 of 5

Thread: Query Not Working?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    95

    Query Not Working?

    Here's my code:
    PHP Code:
    <style type="text/css">
    <!--
    .b {
        font-weight: bold;
    }
    .red {
        color: #F00;
    }
    -->
    </style>
    <form action="" method="post">
    <table width="310" height="32" border="0">
      <tr>
        <td width="137">Login Name:</td>
        <td width="264"><input type="text" name="username"></td>
      </tr>
      </table>
    <p class="red"><span class="b">This is NOT your character's name </span>
    </p>
    <p class="red"><input type="submit" value="Vote" name="vote"></p>
    <?php
    $user 
    mysql_real_escape_string($_POST['username']);
    $ucheck mysql_query("SELECT * FROM `accounts` WHERE `name`='".$user."'") or die(mysql_error());
    $votecheck mysql_query("SELECT * FROM `accounts` WHERE `name` = '".$user."' && `votedtoday` != 1") or die(mysql_error());
    $alreadyvoted mysql_num_rows($votecheck);
    if(isset(
    $_POST['vote'])){
    if(
    mysql_num_rows($ucheck) >= 1){
        if(
    alreadyvoted >= 1) {
            
    mysql_query("UPDATE `accounts` SET `paypalNX` = paypalNX + 10000 WHERE `name` = '".$user."'") or die(mysql_error());
            
    mysql_query("UPDATE `accounts` SET `votedtoday` = 1 WHERE `name` ='".$user."'") or die(mysql_error());
            echo 
    "Successfully added 10k NX to your account, if you are currently logged in, relog. You will now be redirected.";
            echo
    "
            <META HTTP-EQUIV=\"refresh\" CONTENT=\"1;URL=http://www.gtop100.com/in.php?site=39688\">
            "
    ;
        }
        else{
            echo 
    "You have already voted today, come back tomorrow!";
            }
    }
        else{
            echo 
    "Username does not exist.";
        }

    }
    ?>
    </form>
    But when I use it, even if votedtoday = 0 it will still say they have already voted.

    Please help.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Query Not Working?

    The SQL looks fine. How is "votedtoday" set up? Do you have a cron script that sets the entire table's "votedtoday" value to 0 at midnight, or something?

    After writing that, I noticed your error. You are checking the constant that doesn't exist, 'alreadyvoted,' rather than the variable $alreadyvoted. Just change that and everything should work fine.

    This line:
    PHP Code:
        if(alreadyvoted >= 1) { 

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    95

    Re: Query Not Working?

    After all that, I made a basic mistake >_>

    I forgot to use $alreadyvoted instead of alreadyvoted.

  4. #4
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Query Not Working?

    Yeah it is easy to forget the $ in front of php variables sometimes! Especially when you have a lot of code to deal with.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  5. #5
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Query Not Working?

    might i suggest getting UltraEdit for coding php/html etc... it has syntax highlighting for PHP, html, css, js, java, perl, vb, c++, MySQL.. etc its very nice and worth the $!!! it makes it easy to see when you miss a $ because of the coloring.
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width