|
-
Oct 5th, 2005, 04:44 PM
#1
Thread Starter
Hyperactive Member
Register / Login
Ok, So I am just learning PhP, and I havent learned too much, but Im getting the basic Idea of it. I tend to work better when I have examples to look at.. Can someone help me out with some example code for a working user registration and Login page? I cant find any...Anywhere.
You win some, you lose some.
-
Oct 5th, 2005, 06:12 PM
#2
Hyperactive Member
-
Oct 5th, 2005, 06:17 PM
#3
Re: Register / Login
Here is a basic login script. HTH 
PHP Code:
<?php
$username = $_POST['username'];
$email = $_POST['email'];
if (!isset($_POST['submit'])) { // if form hasn't been submitted to itself then show form
?>
<html>
<head>
<title>Lintz's Test Login</title>
</head>
<body><center>
<b><font size="6">Please enter your username and email address to login</font></b>
<p>
<form method="POST" action="<?php echo $PHP_SELF;?>">
<table border="1" style="border-collapse: collapse" bordercolor="#111111" width="580">
<tr>
<td width="580">
<table border="0" cellpadding="1" width="100%">
<td width="35%"><font face="Verdana" size="2"><b>Your Name:</b></font></td>
<td width="65%"><input type="text" name="username" size="65"></td>
</tr>
<tr>
<td width="35%"><font face="Verdana" size="2"><b>Email Address:</b></font></td>
<td width="65%"><input type="text" name="email" size="65"></td>
</tr>
<tr>
<td colspan="2" align="center"><br>
<input type="submit" value="Login" name="submit" style="font-family: Verdana; font-size: 10pt; font-weight: bold"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<?
}
else {
/*This is where you need to check the details the user has entered to make sure
they match what is in your database*/
if ($username == "UserName In Yr Database") {
//This shows the user who has submitted the detials, what details have been submitted.
echo "Thank you for logging in<p>";
echo "Your username is $username and your email address is $email.";
}
else {
echo "Login failed. Please check your details and try again";
}
}
?>
-
Oct 5th, 2005, 07:08 PM
#4
Hyperactive Member
Re: Register / Login
mine uses MySQL his doesnt...ur choice on wat u prefer
-
Oct 5th, 2005, 07:12 PM
#5
Re: Register / Login
Ninja, I was a little lazy as I put a comment in saying to check the username entered is in his database.
-
Oct 5th, 2005, 07:22 PM
#6
Hyperactive Member
-
Oct 5th, 2005, 07:24 PM
#7
Thread Starter
Hyperactive Member
Re: Register / Login
Wow, Thank you alot...Yeah, I would like to Use Sql, Ill take a look at the examples you guys gave me in a minute....Is there one for registering you could show me an example of too?
You win some, you lose some.
-
Oct 5th, 2005, 07:27 PM
#8
Re: Register / Login
Ninja's example does that as well
-
Oct 5th, 2005, 07:33 PM
#9
Thread Starter
Hyperactive Member
Re: Register / Login
Yes, I saw that, And thanks once again. I have one more thing I could use a little basic help on, Its alot easier to understand things with asking + examples then looking on all the sites I've been to. I just need some basics on Databases, Indexes, Auto Increments, and all that good junk...Surprisingly, I dont get it.
You win some, you lose some.
-
Oct 5th, 2005, 07:57 PM
#10
Hyperactive Member
Re: Register / Login
php.net and mysql.com have good things and remember...google is ur friend
-
Oct 5th, 2005, 07:59 PM
#11
Hyperactive Member
Re: Register / Login
indexes like array indexes? and auto increments like
<?php
if (x < 10)
{
x++;
}
echo "x";
?>
???? databases i dont really no but other ppl do
-
Oct 5th, 2005, 08:28 PM
#12
Thread Starter
Hyperactive Member
Re: Register / Login
Yes, ive been using google, but the tutorials and anything I find are too general, They dont have specifics on how to actually read from the DB and stuff, but Im sure i can find it if i spend some more time on it...
By indexes and Auto-Increments, I meant in the Database/Table itself....Like im going to be making a text-based RPG, And Its obviously going to use alot of tables....For now i think im going to be making one table, with all the info it in, And i need to know how to read/write from it so that i can look up the user's name and get their gold/army size....all that junk just from looking up their name.
You win some, you lose some.
-
Oct 5th, 2005, 08:44 PM
#13
Re: Register / Login
Try this.
PHP Code:
$sql = "SELECT * from YourTable WHERE userID = '1'"; //Tell database what to get
$result = mysql_query($sql) or die("Error getting user info<br>".mysql_error()); // Pulls what we want from the database
//Now loop through all records from query
while ($UserDetails = mysql_fetch_row($result)) {
echo "$UserDetails[0]<br>"; //field one from table
echo "$UserDetails[1]<br>"; //field two from table
echo "$UserDetails[2]<br>"; //field three from table
}
-
Oct 5th, 2005, 08:46 PM
#14
PowerPoster
Re: Register / Login
 Originally Posted by psycopatchet69
Yes, ive been using google, but the tutorials and anything I find are too general, They dont have specifics on how to actually read from the DB and stuff, but Im sure i can find it if i spend some more time on it...
By indexes and Auto-Increments, I meant in the Database/Table itself....Like im going to be making a text-based RPG, And Its obviously going to use alot of tables....For now i think im going to be making one table, with all the info it in, And i need to know how to read/write from it so that i can look up the user's name and get their gold/army size....all that junk just from looking up their name.
Post what your table will look like and we'll try and give you a general idea on how to structure it. Generally the smaller the tables the better as it can take a long time to search through a really large table.
-
Oct 5th, 2005, 08:49 PM
#15
Thread Starter
Hyperactive Member
Re: Register / Login
Now can you please explain what that does? lol
More specific - I have a table named Info, and in the table there are 3 field, Name, Gold, Army....Now, How do I Tell it to take name = Psycopatchet, and return me the gold and army size? And also, How to locate those values for maniplulation.
You win some, you lose some.
-
Oct 5th, 2005, 08:57 PM
#16
Thread Starter
Hyperactive Member
Re: Register / Login
Ok, as an addon to my question(s), This may sound stupid..But in the "mysql_query($query,$link)" statement, I put a link to my database, right?
You win some, you lose some.
-
Oct 5th, 2005, 09:08 PM
#17
Re: Register / Login
A mod from my previous example.
PHP Code:
$sql = "SELECT * from Info WHERE Name = 'Psycopatchet'"; //Tell database what to get
$result = mysql_query($sql) or die("Error getting user info<br>".mysql_error()); // Pulls what we want from the database
//Now loop through all records from query
while ($UserDetails = mysql_fetch_row($result)) {
echo "Name = $UserDetails[0]<br>"; //field one from table
echo "Gold = $UserDetails[1]<br>"; //field two from table
echo "Army = $UserDetails[2]<br>"; //field three from table
}
-
Oct 5th, 2005, 09:34 PM
#18
PowerPoster
Re: Register / Login
 Originally Posted by psycopatchet69
Now can you please explain what that does? lol
More specific - I have a table named Info, and in the table there are 3 field, Name, Gold, Army....Now, How do I Tell it to take name = Psycopatchet, and return me the gold and army size? And also, How to locate those values for maniplulation.
User Table
User ID = Auto increment
Name = String
Any other person details
Info Table (you could probably think up a better name than that )
User ID
Gold = Integer
Army = Integer?
So your query will end up looking something like,
SELECT GOLD, ARMY FROM INFO,USER WHERE USER.UID = INFO.USERID AND USER.NAME = "Some Fellars Name"
-
Oct 5th, 2005, 09:46 PM
#19
Re: Register / Login
"Some Fellars Name", only us Aussies would use a phrase like that
-
Oct 7th, 2005, 10:55 AM
#20
Hyperactive Member
Re: Register / Login
http://phpfreaks.com have sum good tuts.... I learnt pagination from them.
Without balance, there could only be chaos.
Without chaos, there could be no balance.
I live with karma. Eat with destiny. Dream of life without shackles....
Yet. If life had no consequences, life could not exist, nor could it flourish.
If at first you dont succeed.You're screwed.
C++/Java NOOB.
I aint a professional at PHP, but if i can help i will.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|