NameSilo

PHP and MYSQL help needed

Spaceship Spaceship
Watch
Impact
19
Hey
I have been posting for help for awhile regarding php and stuff..i also posted the reason that i am working on a game on TURING [OLD PROGRAMING LANGUAGE] and the only way for me to make it online is to use PHP to store data in MYSQL...its quite complicated..

anyway, i can send data to the database and all..but i cant seem to figure out this:

The Login system...I searched online..and all the php logins i could find used sessions...i dont wnat that..since i am using turing with it..i just want to:

Check the database for the username and the password that i get from the USER and check it against the database..and if it exsists then it puts "LOGED IN" otherwise "Wrong username/password"

and i also want [for the registration] to see if the username that USER chose is taken or not..and email adress.

so i just want some IF statements but i cant seem to figure out how to do it
Thanks
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Hi,

The problem with your approach is that when you are using several pages/scripts which should be behind the login, everytime one of them is requested, the user has to be authorized all over again. Since sessions are used to remember if a user has performed a succesfull login, you should find another away to maintain this feature.

I don't know much about Turing but can't you just this language to set a cookie to store a session id? Or use it to encode something in the query string? If you're able to do this, you can just build your own session implementation using Turing.

best of luck!

-monty
 
0
•••
well i am going to build my own session implementation in turing..but i need help with the PHP part as i m not much of a php programmer
i need to know

1. How to Check if the Username and the password that was inputed matches the one in the Database...

2. [For registration]: if the user that was inputed already exists
 
0
•••
Anyone
this is urgent:(
 
0
•••
This is a part from my code, hope it helps



PHP:
 $sql_username_check = mysql_query("SELECT username FROM users 
             WHERE username='$username'");
 
 $username_check = mysql_num_rows($sql_username_check);
 
 if(($email_check > 0) || ($username_check > 0)){
     echo "There were some errors: <br />";
     if($email_check > 0){
         echo "<strong>Your email address is already taken, or you are trying to register twice. Only one registration per person!<br />";
         unset($email);
     }
     if($username_check > 0){
         echo "Someone has already signed up with your username. Try making a different one.<br />";
         unset($username);
     }
     include 'register.htm'; 
     exit();  
 }
 
0
•••
thats awesome :D Now for the Login..to see if the username and password is right...
 
0
•••
$sql="select user,pass from info where user='$user',pass='$pass' ";

something like this do the trick
 
0
•••
JFS said:
$sql="select user,pass from info where user='$user',pass='$pass' ";

something like this do the trick
PHP:
$sql = "select user, pass from info where user='$user' AND pass='$pass'";
 
0
•••
thanks SecondVersion for correcting me, i write that from head and i didn't remember the 'and'
thanks;)
 
0
•••
SecondVersion said:
PHP:
$sql = "select user, pass from info where user='$user' AND pass='$pass'";
yea but what if they dont exsist?
 
0
•••
unknowngiver said:
yea but what if they dont exsist?
Something like...
PHP:
$sql = mysql_query("
    SELECT user, pass 
    FROM info 
    WHERE user='$user' 
        AND pass='$pass'
    LIMIT 1
");

if (mysql_num_rows($sql) > 0)
{
    // Entered correct user/pass
}
else
{
    // Wrong user/pass
}
 
0
•••
great
just curious..what is
PHP:
Limit 1
for?
 
0
•••
it bet is the number of that certain thing that they are showing.
 
0
•••
unknowngiver said:
great
just curious..what is
PHP:
Limit 1
for?

The LIMIT clause in sql statements tells sql
once a match is found, only use X AMOUNT.

In this case, since you are searching for a specific Member,
once the match is found, LIMIT 1 tells it to stop and return the value
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back