I have two tables in MYSQL, tblLogin and tblCustomers with the following Columns: tblLogin{LoginID as Primary_Key, UserName, Password} and tblCustomer{Customer_ID as Primary_Key, Customer_FullName, OrderID, OrderDetails, submission_date, Customer_LoginID as Foreign_key}.
What I want is to let customers to view their own records only due to their login information.
To accomplish this I set two forms namely Login_Form.php and Results.php where after pressing SUBMIT BUTTON of Login_Form.php the user should be able to see his own records displayed on Results.php form dynamically.
Here is my code for these forms!
1. Login_form.php
Expand|Select|Wrap|Line Numbers
- <html>
- <head>
- <meta content="text/html; charset=ISO-8859-1"
- http-equiv="content-type">
- <title></title>
- </head>
- <body>
- <form target="_self" enctype="text/plain" method="post"
- action="Results.php" name="Login_Form"><label>User
- name</label>
- <label>Password<br> <br> </label><input name="UserName" value="User Name">
- <input name="Password" value="Password"
- type="password"><br>
- <br>
-
- <input name="Submit" value="submit"
- type="submit"><br>
- <br>
- </form>
- </body>
- </html>
Expand|Select|Wrap|Line Numbers
- <?php
- $dbhost = 'localhost:3306';
- $dbuser = 'root';
- $dbpass = 'rootpassword';
- $conn = mysql_connect($dbhost, $dbuser, $dbpass);
- if(! $conn )
- {
- die('Could not connect: ' . mysql_error());
- }
- $sql = 'Customer_ID, Customer_FullName, OrderID, OrderDetails,submission_date, Customer_LoginID WHERE .....?';
- mysql_select_db('tblCustomers');
- $retval = mysql_query( $sql, $conn );
- if(! $retval )
- {
- die('Could not get data: ' . mysql_error());
- }
- while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
- {
- echo "Customer_ID :{$row['Customer_ID']} <br> ".
- "Full Name: {$row['Customer_FullName']} <br> ".
- "Order Details: {$row['OrderDetails']} <br> ".
- "Date : {$row['submission_date']} <br> ".
- "--------------------------------<br>";
- }
- echo "Fetched data successfully\n";
- mysql_close($conn);
- ?>
Please!!!!