Makeing Resource id #3 the actual result

Discussion in 'PHP' started by D_C, Feb 2, 2008.

  1. #1
    I'll go ahead and show my code, im learning so I dont care.

    I'm creating a REALLY stupid 'game' that is really just a learning experience. Currently, I am trying to make a REALLY BAD LOGIN SYSTEM. I know its REALLY BAD! I'll make the encryption and crap the next time I learn things, I just want to get this script to work. (meaning don't give me 'you did this the really stupid insecure way noob' because I know.)

    Here is the code (password removed)
    
    <?php session_start(); ?>
    
    <html>
    
    <title>Clicking Game!</title>
    
    <body>
    <center>Welcome to the most blandly looking webpage I have ever made, but Im doing it for the php script, not looks.</center>
    
    <p><hr><center><a href=index.php>Home</a> | <a href=signup.php>Signup</a> | <a href=signin.php>Sign in</a> | <a href=click.php> Click!</a></center><p><hr>
    
    <?
    
    $username="root";
    $password="------";
    $database="clickgame";
    
    $uname=$_POST['username'];
    $upass=$_POST['password'];
    
    
    
    mysql_connect(localhost,$username,$password);
    
    mysql_select_db($database) or die("Database could not connect.");
    
    echo " " .$uname ." " .$upass;
    
    $query1="SELECT * FROM users WHERE username='$uname'";
    $query2="SELECT * FROM users WHERE password='$upass'";
    
    $result=mysql_query($query1);
    $result2=mysql_query($query2);
    
    $sol=mysql_fetch_field($result);
    $sol2=mysql_fetch_field($result2);
    
    echo " " .$result ." " .$result2;
    
    if($sol==$uname)
    {
    	 $_SESSION['usrname'] = $uname;	
    }
    else
    {
    	echo "Didn't Work!";
    }
    
    if($sol2==$upass)
    {
    	$_SESSION['pssword'] = $upass;
    }
    else
    {
    	echo "Didn't Work2!";
    }
    
    echo "You are now logged in.";
    
    
    ?>
    
    
    <br><Br><br><br>Created By: Chris Morin
    
    </body>
    
    </html>
    
    PHP:
    It returns:

    Only problem I can see (well... you know what I mean) is that I can't get 'Resource id #3 and #4' to be what they actually are finding in the database. So what function should I use? Or how can I make this work?

    Thanks alot,

    D_C
     
    D_C, Feb 2, 2008 IP
  2. nile1483

    nile1483 Active Member

    Messages:
    345
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    60
    #2
    check it with

    $result=mysql_query($query1)->name;
    $result2=mysql_query($query2)->name;
     
    nile1483, Feb 2, 2008 IP
  3. D_C

    D_C Well-Known Member

    Messages:
    1,107
    Likes Received:
    21
    Best Answers:
    1
    Trophy Points:
    160
    #3
    Now I get:
    Code Now:
    
    <?
    
    $username="root";
    $password="-----";
    $database="clickgame";
    
    $uname=$_POST['username'];
    $upass=$_POST['password'];
    
    
    
    mysql_connect(localhost,$username,$password);
    
    mysql_select_db($database) or die("Database could not connect.");
    
    echo " " .$uname ." " .$upass;
    
    $query1="SELECT * FROM users WHERE username='$uname'";
    $query2="SELECT * FROM users WHERE password='$upass'";
    
    $result=mysql_query($query1)->name;
    $result2=mysql_query($query2)->name;
    
    $sol=mysql_fetch_field($result);
    $sol2=mysql_fetch_field($result2);
    
    echo " " .$result ." " .$result2;
    
    if($sol==$uname)
    {
    	 $_SESSION['usrname'] = $uname;	
    }
    else
    {
    	echo "Didn't Work!";
    }
    
    if($sol2==$upass)
    {
    	$_SESSION['pssword'] = $upass;
    }
    else
    {
    	echo "Didn't Work2!";
    }
    
    echo "You are now logged in.";
    
    
    ?>
    
    PHP:
     
    D_C, Feb 2, 2008 IP
  4. nile1483

    nile1483 Active Member

    Messages:
    345
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Sorry try here



    $sol=mysql_fetch_field($result)->name;
    $sol2=mysql_fetch_field($result2)->name;


    because you Must define What data you want from field like field name(name), data type etc.


    Return Values

    Returns an object containing field information. The properties of the object are:

    * name - column name
    * table - name of the table the column belongs to
    * def - default value of the column
    * max_length - maximum length of the column
    * not_null - 1 if the column cannot be NULL
    * primary_key - 1 if the column is a primary key
    * unique_key - 1 if the column is a unique key
    * multiple_key - 1 if the column is a non-unique key
    * numeric - 1 if the column is numeric
    * blob - 1 if the column is a BLOB
    * type - the type of the column
    * unsigned - 1 if the column is unsigned
    * zerofill - 1 if the column is zero-filled

    check it http://in2.php.net/mysql_fetch_field
     
    nile1483, Feb 2, 2008 IP
    D_C likes this.
  5. D_C

    D_C Well-Known Member

    Messages:
    1,107
    Likes Received:
    21
    Best Answers:
    1
    Trophy Points:
    160
    #5
    I see what you're saying, and it makes sense and I think I'm on the right track. But for some reason that returns 'id' for both querys. I changed the code to this to check:

    
    <?php session_start(); ?>
    
    <html>
    
    <title>Clicking Game!</title>
    
    <body>
    <center>Welcome to the most blandly looking webpage I have ever made, but Im doing it for the php script, not looks.</center>
    
    <p><hr><center><a href=index.php>Home</a> | <a href=signup.php>Signup</a> | <a href=signin.php>Sign in</a> | <a href=click.php> Click!</a></center><p><hr>
    
    <?
    
    $username="root";
    $password="----";
    $database="clickgame";
    
    $uname=$_POST['username'];
    $upass=$_POST['password'];
    
    
    
    mysql_connect(localhost,$username,$password);
    
    mysql_select_db($database) or die("Database could not connect.");
    
    echo " " .$uname ." " .$upass;
    
    $query1="SELECT * FROM users WHERE username='$uname'";
    $query2="SELECT * FROM users WHERE password='$upass'";
    
    $result=mysql_query($query1);
    $result2=mysql_query($query2);
    
    $sol=mysql_fetch_field($result)->name;
    $sol2=mysql_fetch_field($result2)->name;
    
    
    echo " " .$sol ." " .$sol2;
    
    if($sol==$uname)
    {
    	 $_SESSION['usrname'] = $uname;	
    }
    else
    {
    	echo "Didn't Work!";
    }
    
    if($sol2==$upass)
    {
    	$_SESSION['pssword'] = $upass;
    }
    else
    {
    	echo "Didn't Work2!";
    }
    
    echo "You are now logged in.";
    
    
    ?>
    
    
    <br><Br><br><br>Created By: Chris Morin
    
    </body>
    
    </html>
    
    PHP:
    and it all returned:

    Thanks so much for you help! Rep Added.
     
    D_C, Feb 2, 2008 IP
  6. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #6
    other way to print the coloumns is like $result['name']

    Regards

    Alex
     
    kmap, Feb 3, 2008 IP
  7. D_C

    D_C Well-Known Member

    Messages:
    1,107
    Likes Received:
    21
    Best Answers:
    1
    Trophy Points:
    160
    #7
    I'm not trying to print columns, I'm trying to call the data and make it a var.
     
    D_C, Feb 3, 2008 IP