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
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:
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
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.