The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 2 of 2

Thread: How can I Retrieve a record in mysql?

  1. #1

    How can I Retrieve a record in mysql?

    hello everyone! I have a problem with my login code... I have here a code that deals with an empty result set in mysql... I have already dealt with that problem. However, I got into another problem which is the retrieval of a record if the result set is not empty... I am hoping for your reply.. thanks!

    if($row=mysql_num_rows($result)==0){
    echo "EMPTY";
    }
    else{
    while($row=mysql_fetch_assoc($result)){
    $userID=$row['id_num'];
    $userName=$row['name'];
    $userPass=$row['password'];
    echo "<form action='index.php' method='POST'>";
    echo "<input type='hidden' name='userID' value='$userID'>";
    echo "<input type='hidden' name='userName' value='$userName'>";
    echo "<input type='hidden' name='userPass' value='$userPass'>";
    echo "</form>";
    }

    $userID=isset($_POST['userID']) ? $_POST['userID'] :"";
    $userPass=isset($_POST['userPass']) ? $_POST['userPass'] :"";
    $userName=isset($_POST['userName']) ? $_POST['userName'] :"";

    echo "JUST CHECKING---<br>input: $id<br>$pass2<br>Table:$userID<br>$userPass<br>---<br>";

    if($userID==""&&$userPass){
    echo "<br>No Entry";
    }
    if($pass2!=$userPass){//password field is empty or mismatch
    echo "Passwords do not match";
    }
    if($id!=$userID){
    echo "<br>ID numbers do not match";
    }
    else{
    echo "Welcome $userName";
    }
    }

  2. #2
    439
    posts
    Registered User
    Not quite sure what you mean. But I've had a look at your code and modified some of the conditionals. Could you explain more on what the problem is?

    PHP Code:
    <?php

    if(mysql_num_rows($result) == 0)
    {
        echo 
    "EMPTY";
    }else{

        while(
    $row mysql_fetch_assoc($result))
        {
            
    $userID        $row['id_num'];
            
    $userName    $row['name'];
            
    $userPass    $row['password'];
            echo 
    "<form action='index.php' method='POST'>";
            echo 
    "<input type='hidden' name='userID' value='$userID'>";
            echo 
    "<input type='hidden' name='userName' value='$userName'>";
            echo 
    "<input type='hidden' name='userPass' value='$userPass'>";
            echo 
    "</form>";
        }

        
    $userID        = isset($_POST['userID']) ? $_POST['userID'] :"";
        
    $userPass    = isset($_POST['userPass']) ? $_POST['userPass'] :"";
        
    $userName    = isset($_POST['userName']) ? $_POST['userName'] :"";

        echo 
    "JUST CHECKING---<br />input: $id<br />$pass2<br />Table:$userID<br />$userPass<br />---<br />";
        
        if(
    $userID != "" && isset($userPass))
        {
            echo 
    "<br />No Entry. Please try again";
            
        }else{
        
            if(
    $pass2 != $userPass)
            {
    //password field is empty or mismatch
                
    echo "Passwords do not match";
            }else{
                        
                if(
    $id != $userID)
                {
                    echo 
    "<br />ID numbers do not match";
                }else{
                    echo 
    "Welcome $userName";
                }
            }    
            
        }
    }

    ?>
    while ( ! ( succeed = try() ) );

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012