Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2005
    Posts
    279
    Thanks
    0
    Thanked 0 Times in 0 Posts

    getting data from mysql "correct and incorrect"

    Guys, my logic is not working very well .
    PHP Code:
    <?php

    include 'config.php';
    include 
    'opendb.php';

    if (isset(
    $_GET['verify']))
    {
       
    $code $_GET['code'];
       
    $active "not";
       
       
    $query1 "SELECT UserID, Activity from Member";
       
    $result mysql_query($query1) or die ('Error, query failed' .mysql_error());
       
       while (
    $user mysql_fetch_array($resultMYSQL_NUM))
       {
             
    // if the code entered is the sasm as UserID in the member table
             
    if ($code == $user[0])
             {
                
    $query2 "UPDATE member SET Activity = '$active' WHERE UserID = '$code'";
                
    mysql_query($query2) or die ('Error, query failed' .mysql_errno());
                echo 
    "Correct";
             }

       }
       if (
    mysql_query("SELECT UserID from Member WHERE UserID = '$code'")) {
          echo 
    "incorrect";
       }
    }
    include 
    'closedb.php';

    ?>
    If I put the right "code", I got the output "correctincorrect" I dont' want the output incorrect, how can I resolve this?

  • #2
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Hi cgibie,
    This part just checks whether the query is a valid. I figure that you instead want to know whether there are any rows returned from the query?
    PHP Code:
    if (mysql_query("SELECT UserID from Member WHERE UserID = '$code'")) {
      echo 
    "incorrect";

    Try using mysql_num_rows() to count the rows.
    PHP Code:
    $result mysql_query("SELECT UserID from Member WHERE UserID = '$code'");
    if (
    mysql_num_rows($result)) {
      echo 
    "incorrect";



  •  

    Posting Permissions

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