[Solved] Simple PHP/MySQL sign up and login script?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Jeefo
Forum Newbie
Posts: 16
Joined: Thu Jun 16, 2005 3:38 pm
Location: Tokyo, Japan

[Solved] Simple PHP/MySQL sign up and login script?

Post by Jeefo »

(Please read whole post.)

Well I've been searching the internet the whole day for some PHP/MySQL signup and login scripts. There is no luck whatsoever.

Can someone point me in the direction (or make me one ^_^) of a simple signup and login script?

OR...I did find this tutorial on how to make one and it did work. The only problem is is that no matter what account you login with, it goes to the same page (getin.php). If anyone could tweak it so it redirects to a certain page depending on the user, it would be very appreciated! (Codes below)

(Example: someone logins with username: hello --> redirects to hello.php)

login.php: (login page)

Code: Select all

<form action="getin.php" method="post">
Username: <input type="text" name="username" size="10"><p>
Password: <input type="password" name="password" size="10"><p>
<input type="submit" value="Login" name="submit">
</form>
getin.php: (login code)

Code: Select all

<?
$conn = mysql_connect("localhost","****","****");
$db = mysql_select_db("****");

$username = $_POST["username"];
$password = $_POST["password"];

$result = MYSQL_QUERY("SELECT * from users WHERE username='$username'and password='$password'")
   or die ("Name and password not found or not matched");

$worked = mysql_fetch_array($result);

$username = $worked[username];
$password = $worked[password];
$email = $worked[email];

?>
<?
if($worked)
   echo "Welcome $username! Please wait. Contacting database..."; 
?>
I don't know if it would help, but here is make.php (the script to create an account):

Code: Select all

<?
$conn = mysql_connect("localhost","****","****");

$db = mysql_select_db("****");

$username = $_POST["username"];
$password = $_POST["password"];
$email = $_POST["email"];

$result= MYSQL_QUERY("INSERT INTO users (id, username, password, email)".
   "VALUES ('NULL', '$username', '$password', '$email')");
   
echo "Your name and password have been submitted into our database.";
?>
P.S. ---------------------
I know the redirection thing isn't the most secure, but my site uses IFrames and I have a no right-click script on every page so it's impossible to hack....right?

P.P.S. ---------------------
Yes, the actual database names and passwords are intact.

Thank you!
Last edited by Jeefo on Thu Aug 25, 2005 5:14 pm, edited 1 time in total.
User avatar
AnarKy
Forum Contributor
Posts: 119
Joined: Tue Nov 02, 2004 1:49 am
Location: South Africa

die

Post by AnarKy »

Code: Select all

or die ("Name and password not found or not matched");
The die part is what happens if the query was not successful!
Even if there are no rows returned, the query is still successful, but with an empty dataset.
User avatar
AnarKy
Forum Contributor
Posts: 119
Joined: Tue Nov 02, 2004 1:49 am
Location: South Africa

store hompage.

Post by AnarKy »

Hi,

just as a thought, you may modify your table that stores the uid's and p/words
so that it also stores the users default page.

So when a user enters the uid and p/words, you can extract his/her landing page and redirect them to it.
Simple :wink:
Post Reply