Lesson #2 - Installing The Databases part 2
part 2.
</tr>
<tr>
<td style="padding-left:20px; padding-top:10px; height:20px; width:200px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px" align="left" valign="middle">age:</td>
<td style="width:300px;padding-left:20px; padding-top:10px;" align="left" valign="middle">
<input name="age" type="text" size="40" maxlength="2">
</td>
</tr>
<tr>
<td style="padding-left:20px; padding-top:10px; height:20px; width:200px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px" align="left" valign="middle">city:</td>
<td style="width:300px;padding-left:20px; padding-top:10px;" align="left" valign="middle">
<input name="city" type="text" size="40" maxlength="40">
</td>
</tr>
<tr>
<td style="padding-left:20px; padding-top:10px; padding-bottom:10px; height:20px; width:200px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px" align="left" valign="middle">country:</td>
<td style="width:300px;padding-left:20px; padding-top:10px; padding-bottom:10px;" align="left" valign="middle">
<input name="country" type="text" size="40" maxlength="40">
</td>
</tr>
<tr>
<td colspan="2" style="background-color:#FF9900;padding-left:20px; height:35px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px" align="left" valign="middle">
<input type="button" value="register" width="40">
</td>
</tr>
</form>
</table>
Next, create file in same directory and name it add_user.php. This is the file that will process our registration.
#below we set the database connection parameters. these i usually keep in an external file but for our purposes, we shall leave them within. please substitute the values with those on your system
$db_host = localhost #your database server
$db_user = admin #your database user
$db_pass = admin #your database password
$db_name = gorillanet #wat database you are using
#below, we use the set parameters to connect to our server, select the database of interest and create a user table in it.
mysql_connect($db_host,$db_user,$db_pass)or die(mysql_error());
mysql_select_db($db_name)
sql_query("INSERT INTO gorillanet_users (user_name, password, user_email, user_sex, user_city, user_country, user_age) VALUES ('".$_POST['username']."', '".md5($_POST['password'])."', '".$_POST['email']."', '".$_POST['sex']."', '".$_POST['city']."', '".$_POST['country']."', '".$_POST['age']."')");
header('Location: login_user.php');
Finally, on successful registration, you should be directed to a login page or home page. In this case, we use a dummy login page, login_user.php. Create such a file and add to it this code.
<table style="margin-top:50px; margin-left:50px; width:500px; background-color:#FFE4CA" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" style="height:35px; background-color:#FF9900; padding-left:20px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:16px; color:#FFFFFF; font-weight:bold" valign="middle">Login Here</td>
</tr>
<tr>
<td colspan="2" style="padding-left:20px; padding-right:20px; padding-top:10px; padding-bottom:10px; height:50px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px" align="left" valign="middle">your login form should go here. next, we shall be tackling user processing and login. for now, try to add more fields to your user_table and figure out how to login.</td>
</tr>
</table>
Now, I leave it up to you to figure out how to process user login. Try and create a login form using the registration form as a template. Next week, we shall login the user to his/her personal page and be able to add fields to the user profile.
We shall add a user search mechanism and finalise the basic layout into php code.
The layout will have a header section which contains the logo and menus and a footer section to carry policy, terms and copyright links.. The main section of our layout will be made of the requested pages. This means, no matter which page is visited, our layout will always carry the same header and footer. For today's example, if we had a header, it would be included at the top of each of our php scripts. the footer at the bottom of each.
Homework:
1. create a login form and try to process user logins. On successful logins, the user should be directed to a page with the greeting "Welcome user_name". If the login fails, user should be shown error message.
2. do error controlling in the registration form and registration processing mechanism. an example is, preventing similar usernames, empty fields e.t.c
3. find a way to include reduntant code into all files that may require it without re-typing the code over and over. an example is the styling of our tables and text and also the database connection parameters.
Next week, we code our layout to include the logos and images and successfully login our users to their respective pages.
Good luck!
ps: all tutorial related questions can be sent to my personal inbox.
seriously, if you find my post helpful, please add it to my rep