Jump to content

Where to go from here...?


GunnDawg

Recommended Posts

Well I am rather new to PHP and mysql and have recently accomplished what I set out to learn in the first place.

 

I am running on a local server so I cannot share it with you unfortunately.

 

Anyways, I have made a basic register script that lets you input a username and password which then writes the data to my db. I also have a page that lists all of the users that have signed up. My question is what should/could I add to this little test project I have going to help further my knowledge and learning?

Link to comment
Share on other sites

look at forum software for ideas

 

do you have login/logout features?

 

can each user have a profile?

 

allow each user to upload an image this will give you some experience with the image functions.

 

moving and renaming images etc.

 

How about trying to do the same thing again but using an OO approach?

Link to comment
Share on other sites

Not sure what a "OO" is unfortunately.

 

Also, no there is no login feature (therefore no log out feature), I have not gotten that far. I am not quite familiar with setting everyone up with their own profile or how to work SESSIONS yet.

 

I suppose I should work on that ?

Link to comment
Share on other sites

Care to point me into the first step into setting up the login page?

 

I would assume it has something to do with setting up a POST forum that will post to like login.php..

 

then pull the data from the form....  then somehow run a check to see if the user name entered matches any of the user names in the db?

Link to comment
Share on other sites

Yeh, the first step would be understanding POST forms.

 

so, create your form:

<form action="thispage.php" method="post">
<input type="text" name="username"/>
<input type="password" name="pass"/>
<input type="submit"/>
</form>

 

so that's your basic login form. It will just have two input boxes and a submit button all on the same line. Appearance doesn't matter right now.

 

What you want to do is get whatever you put into those boxes and them shove them into a variable - which is the most important concept of php. Variables are *everything*.

 

here is how you would get username into a variable.

 

$user = $_POST['username'];

 

now that would go straight above your form because you are submitting your form to the same page.

 

Then, you have to learn a little validation...which means an if statement, at least.

 

So, check if a username has been added...if it has, continue, if not, end or return with a message:

 

(remember $user from before)

1  if ($user != "") {
2  //continue - run the script
3  } else {
4 //display the form

 

so, line 1-3 says --- if $user is not blank do whatever is in between { and }

line 3 has else, which obviously means if $user is anything but blank, display the form.

 

This is validation at it's most basic. Any way, this is how the final script would look. All the same file.

 

<?php

$user = $_POST['username'];

if ($user != "") {

//continue - run the script

} 
else { 
//display the form

?>

<form action="thispage.php" method="post">
<input type="text" name="username"/>
<input type="password" name="pass"/>
<input type="submit"/>
</form>
<?php } ?>

Just copy and paste that into a file and have a little mess about with it.

 

I really hope that helps at least a little bit. You'll get the hang of it eventually.

Link to comment
Share on other sites

here i took it a little further for you. See the use of these functions

 

empty()

isset()

trim()

 

try and implement some password checking and get back to us if you have any problems

 

<?php

if(isset($_POST['login'])) { //proccess POST variables

$user = trim($_POST['username']); //trim removes all white space from the begining and end 

if (empty($user)) {

echo "Please enter your Username";

} //end of if empty 
else { echo "Hello $user"; }

}//end of if(isset 

else { 
//display the form

?>

<form action="" method="post">
<table>
<tr>
<td><label for="Username">Username</label></td><td><input type="text" name="username"/></td>
</tr>
<tr>
<td><label for="Username">Password</label></td><td><input type="password" name="pass"/></td></tr>
<tr>
<td><input type="submit" name="login" value="Login"/></td>
</tr>
</table>
</form>
<?php } ?>

Link to comment
Share on other sites

lol I know how to copy/paste just not sure how to post "code" on a message....

 

Anyways this is what my current project looks like....(if you care)  :)

 

This is my register page...

 

<html>
<head>
<title>Register</title>
</head>

<body>

<br>

<center><font face="comic sans ms" size="20">Register!</font>

<br><br><br>

<form method="post" action="complete.php">
Username:
<input type="text" name="username" size="30" /><br /><br />
Password:
<input type="password" name="password" size="30" /><br /><br />
<input type="submit" value="Register">
</form>

<br>
<br>

<center><a href="list.php">List of all members</a>[/td]
[/tr]
[/table]


This is the complete.php page that it routes too...

[table]
[tr]
[td]<?php
$username = $_POST['username'];
$password = $_POST['password'];

$link = mysql_connect('localhost');
mysql_select_db('test');

$query="INSERT INTO test_table(autoid, username, password)VALUES ('NULL', '".$username."', '".$password."')";
mysql_query($query, $link) or die ('Error updating database');

echo "You have successfully registered the username: ";
echo "$username";


?>

<html>
<head>
<title></title>
</head>
<body>

<center><a href="list.php">List of all members</a>

</body>
</html>

 

 

And this is the page that lists all of the current registered users...

 

 

<html>
<head>
<title>List of all users</title>
</head>

<body>

<center><font size = "6" face = "comic sans ms">List of all registered users</font></center>


<?php

#Establish a mysql connection
$link = mysql_connect('localhost');

#Check mysql Connection
if (!$link)
{

    	die('Could not connect: ' . mysql_error());
    	exit;

}

#Select and check database validation
if (!mysql_select_db('test', $link))
{
	echo 'Database Failed';
}

#Gather data from the table using a query
$query = "SELECT * FROM test_table";
$result = mysql_query($query, $link);

#Check integrity of the stored data
if (!$result)
{
	echo mysql_error();
}

#Make a loop to to display all rows of data from the query
while ($row = mysql_fetch_assoc($result))

{

	echo $row['username'].'<br>';

}
?>

<center><a href="register.php">Back to Home</a>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.