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 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mysql SELECT issue

    I'm creating a simple login-and-fetch-data site without much security or finesse. What I wan't is to type a string of numbers in one textbox and a password in a second textbox. When submit it will search a database for a record containing both values.

    All I get is Resourse id #4 which indicates that I typed something wrong; Here is the code I use and a picture of phpmyadmin.

    Picture of phpmyadmin and how my database looks



    This is the login page

    PHP Code:
    <div id="formcontainer">
    <
    h3>Logga in här</h3>
    <
    h4>Fyll i auktionsnr och lösenord</h4>
     <
    form method="post" action="data.php">

     <!--
    Auktionsnr-->
      <
    div class="clearfix">
         <
    label>String of numbers: </label>
         <
    input name="aukt" type="text" size="35" />
      </
    div>
     <!--
    Losenord-->
         <
    div class="clearfix">
              <
    label>Password:</label>
             <
    input name="los" type="password" size="35" />
         </
    div

         
    <!--Skicka-knapp-->
         <
    div class="clearfix">
            <
    input name="submit "type="submit" value="Logga in" />
         </
    div>
    </
    form>
    </
    div
    This code gets the string of numbers and a password to check against a database.

    PHP Code:
    <?
        $auktions_nr 
    $_POST['aukt']; // Get textbox value 1
        
    $auktions_losen $_POST['los']; // Get textbox value 2
        
        
    print $auktions_nr// I want to know what I get when debugging so I just print it for now
        
    print $auktions_losen// Same here
        
        
    checkaukpwd($auktionsnr$auktionslosen); // Function I use for checking textboxes
        
        
    @mysql_connect("localhost","root",""// My host (Yeah I dont use password here)
            
    or die("Hittade inte databasen.");
            
        @
    mysql_select_db("tradera"); // The database I use
            
        // This is where things gets weired, I get Resourse id #4 all the time
        
    $query "SELECT *
                  FROM varor
                  WHERE auktionsnr = '$auktions_nr'
                  AND losenord = '$auktions_losen'
                 "
    ;
        
        
    $result mysql_query($query);
        

        
        if (
    $result && mysql_num_rows($result) > 0// Checking for a record that exists with both requirements ($auktions_nr and $auktions_losen).
            
    {
                print 
    "Felaktigt auktionsnr eller lösenord."// If doesn't exist, just stop everything.
                
    exit();
            } else
            {
                print 
    "Woho"// Record found with both requirements. Continue.... (not completed).
            
    }
            
    ?>

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,631
    Thanks
    4
    Thanked 147 Times in 138 Posts
    you're problem is that you are trying to use the resource of the result instead of the result itself.

    after this block:
    PHP Code:
     $result mysql_query($query); 
    you want to use mysql_fetch_row and step through your result and compare it to your database.

  • #3
    New Coder
    Join Date
    Mar 2005
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Perhaps a quick example could be in place? Im not interested in getting everything done for me, I just need code to learn from.

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    http://www.php.net/manual/en/functio...etch-assoc.php <-- Check the examples and comments.


  •  

    Posting Permissions

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