Sunday, 19 July 2009

Admin - View Category

All the product categories for the online shop are listed here. I just select category id, parent id and name and using a while loop we show the category one by one.

Making a admin login page

All user account is saved in tbl_user. For simplicity the table will only contain the bare necessities such as user id and password. You can add more column if you want to.

This is how the login works
1. The admin enter it's username and password
2. The script check whether that username and password combination do exist in the database
3. If it is set the session then go the admin main page
4. If it's not then show an error message
Below is the login form screenshot:



The default user name and password are "admin" ( without the quotes )
and source code of a form



And a script should be on top:



The login function is called doLogin() and it's located in admin/library/functions.php
The checkUser() function look like this :






If the login is successful, this function will set the session variable $_SESSION['plaincart_user_id']. All admin pages will check for this session id using the checkUser() function. If the session id is not found then the function will set a redirection to the login page.

Another thing that this function check is if there's a 'logout' in the query string. If it is then I call the doLogout() function which will remove the session id.
function doLogout()
{
if (isset($_SESSION['plaincart_user_id'])) {
unset($_SESSION['plaincart_user_id']);
session_unregister('plaincart_user_id');
}

header('Location: login.php');
exit;
}
Testing my functions on validation





If all checking validatations are past, then go to customer home page (member area)

Making forgot password page

Firstly, a form, which is created in "forgotPassword.php" file, has an action interracting with "sendPassword.php" file.



the form in Firefox Browser looks like:



In "sendPassword.php" file, I made a connection path



Extracting values from "forgotpassword.php" file



Check if username exist in the database



generate a random password



Update the random password with the old password



Putting my email in header mail and setting up a mail body



Testing my function in Browser:

a form in forgotPassword.php



Validation Checking



After checking, I go back to the form and input "thientanchuong" in the textfield
then I get a confirmed message:




Finally I check the sent password in my email



However, the password is shown in encrypte format, not in normal way. I need to change a line of code which is.



I replaced a variable $upassword with $password. Afterward, I try to send a new password to my email again.



This time is worked.

Make a register page

In my register page I used different php functions to build up:

Firstly, connecting to database hosting which is initilized in config.php
require_once ('../../library/config.php');
then making function for string variable.

mysql_real_escape_string — Escapes special characters in a string for use in a SQL statement.
addslashes — Quote string with slashes.
strip_tags — Strip HTML and PHP tags from a string.
function protect ($string)
{
$string = mysql_real_escape_string ($string);
$string = strip_tags ($string);
$string = addslashes ($string);
return $string;
}
Next, process the form when user click on submit button



Checking data when processing the form





I repeat a register form which will appear the same time with all errors



If there is errror messages when validating all input data, then INSERT input data into hosting database.



When I am testing the register page, I archived some result:

Saturday, 18 July 2009

Error when doing Search Page

I have my source code in my search page following:







When I test the search page, there is error message



Besides that, when I click on another paging such as page 2, It turn out nothing shown up.



Then, I follow the hint from error message, If I try to remove session_start from library/config.php, it will give me more errors.



I post my problems on some forums to achive some solutions. "phpacademy.info"



And get a advise.



and another one in forum "vninformatics.com"



and the solution.



After I get the advise, I move up the code line of "include/config.php" on the top of the page.



and test :



There is no error message but error paging is still appearing, when I click on page 2 for example, the page turns out nothing again:


I noticed that the address bar which is
http://yoongda.com/search.php?page=2&
is missing search value, so address bar shoud show the link:
http://yoongda.com/search.php?page=2&search=a

and I got the solutions from a forum "dynamicdrive.com"




I added $_SESSION variable in search page:



and in common1 page:



I also changed my code following the advise in common1.php:

$strGet ='search'



and add the function "$_SESSION" in the paging links:




And I test my work:



It is working successfully.