GunnDawg Posted October 10, 2008 Share Posted October 10, 2008 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 https://forums.phpfreaks.com/topic/127824-where-to-go-from-here/ Share on other sites More sharing options...
Bendude14 Posted October 10, 2008 Share Posted October 10, 2008 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 https://forums.phpfreaks.com/topic/127824-where-to-go-from-here/#findComment-661746 Share on other sites More sharing options...
GunnDawg Posted October 10, 2008 Author Share Posted October 10, 2008 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 https://forums.phpfreaks.com/topic/127824-where-to-go-from-here/#findComment-661748 Share on other sites More sharing options...
Barand Posted October 10, 2008 Share Posted October 10, 2008 For me, the next step would be to use that data and set up a login page. Then have a couple of other pages - one anyone can access - one only logged in users can access Link to comment https://forums.phpfreaks.com/topic/127824-where-to-go-from-here/#findComment-661750 Share on other sites More sharing options...
GunnDawg Posted October 10, 2008 Author Share Posted October 10, 2008 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 https://forums.phpfreaks.com/topic/127824-where-to-go-from-here/#findComment-661752 Share on other sites More sharing options...
DamienRoche Posted October 10, 2008 Share Posted October 10, 2008 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 https://forums.phpfreaks.com/topic/127824-where-to-go-from-here/#findComment-661760 Share on other sites More sharing options...
Bendude14 Posted October 10, 2008 Share Posted October 10, 2008 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 https://forums.phpfreaks.com/topic/127824-where-to-go-from-here/#findComment-661762 Share on other sites More sharing options...
GunnDawg Posted October 10, 2008 Author Share Posted October 10, 2008 how do I paste my code in here? Link to comment https://forums.phpfreaks.com/topic/127824-where-to-go-from-here/#findComment-661763 Share on other sites More sharing options...
DamienRoche Posted October 10, 2008 Share Posted October 10, 2008 I'm available for private tuition Link to comment https://forums.phpfreaks.com/topic/127824-where-to-go-from-here/#findComment-661764 Share on other sites More sharing options...
Bendude14 Posted October 10, 2008 Share Posted October 10, 2008 first press the # symbol in the little icons when replying then just ctrl+v to paste the code if you already have it copied onto your clipboard. ctrl+c will copy the code out of your editor if you have it highlighted Link to comment https://forums.phpfreaks.com/topic/127824-where-to-go-from-here/#findComment-661765 Share on other sites More sharing options...
GunnDawg Posted October 10, 2008 Author Share Posted October 10, 2008 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 https://forums.phpfreaks.com/topic/127824-where-to-go-from-here/#findComment-661770 Share on other sites More sharing options...
GunnDawg Posted October 10, 2008 Author Share Posted October 10, 2008 not sure why the insert code didnt work... Link to comment https://forums.phpfreaks.com/topic/127824-where-to-go-from-here/#findComment-661772 Share on other sites More sharing options...
trq Posted October 10, 2008 Share Posted October 10, 2008 Quote not sure why the insert code didnt work... You need to put your code within tags. Link to comment https://forums.phpfreaks.com/topic/127824-where-to-go-from-here/#findComment-661780 Share on other sites More sharing options...
GunnDawg Posted October 10, 2008 Author Share Posted October 10, 2008 Thanks for doin that for me Link to comment https://forums.phpfreaks.com/topic/127824-where-to-go-from-here/#findComment-661786 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.