Sunday, 14 June 2009

Display Detail Page with Select box

My idea is to drop down a menu which contains user ID, once user select user ID, it will display more information of the user ID.

Firstly, I made a path which connects to MYSQL database.
include'include/conn.php';
Secondly, I create form :
form method="POST" action="main.php?userID=$userID"
and PHP code inside:



Then a function code that retrieves all data belonging to the user ID that user select.

$display = 'SELECT * FROM user WHERE userID ='.$_GET['userID'];
$result = mysql_query($display, $db)or die(mysql_error($db));

$row = mysql_fetch_assoc($result);
$userID = $row['userID'];
$userName = $row['userName'];
$password = $row['password'];
$fullname = $row['fullName'];
$address1 = $row['address1'];
$address2 = $row['address2'];
$city = $row['city'];
$country = $row['country'];
Display Information:




Testing the result:



I try selecting a user ID to display all data belonging to the user ID:



All errors are viewed as SQL error.

I posted my query on a forum to resolve the problems:



There was a guy in the form support me a hint that is why the problem occurs:




The hint helps me solve it out. I figured out the error caused by
form method="POST" action="main.php?userID=$userID"
In this case, $userID is not a variable, it have to be a string of variable (userID = $userID)

I used isset() function and changed the code.
ISSET() =>determine if a variable is set and is not NULL

If a variable has been unset with unset(), it will no longer be set. isset() will return FALSE if testing a variable that has been set to NULL. Also note that a NULL byte ("\0") is not equivalent to the PHP NULL constant.

If multiple parameters are supplied then isset() will return TRUE only if all of the parameters are set. Evaluation goes from left to right and stops as soon as an unset variable is encountered.

isset() only works with variables as passing anything else will result in a parse error. For checking if constants are set use the defined() function.

When using isset() on inaccessible object properties, the __isset overloading method will be called, if declared.

In the select option, I name it as "selectBox"




Using isset() function. When a user click on submit button, userID will be called.



Display Information



Testing the result:

I have selected user ID as number 6:



No comments:

Post a Comment