MySQL Forums
Forum List  »  PHP

How to set Dynamic WHERE CONDITIONS to show customer rows depending on Login using PHP?
Posted by: Mrkey Lee
Date: March 10, 2013 02:41AM

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
//Begin Login_Form.php
<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> &nbsp;
<label>Password<br> <br> </label><input name="UserName" value="User Name">
&nbsp;<input name="Password" value="Password"
type="password"><br>
<br>
&nbsp;
&nbsp; &nbsp; <input name="Submit" value="submit"
type="submit"><br>
<br>
</form>
</body>
</html>
//End Login_Form.php

2. Results.php
//Begin results.php
<?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 {...YOUR HELP IS NEEDED PLEASE....?}';

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);
?>
//End results.php

Now how to fetch specific data due to specific customer?
Any hint would be highly appreciated
Please!!!!

Options: ReplyQuote


Subject
Written By
Posted
How to set Dynamic WHERE CONDITIONS to show customer rows depending on Login using PHP?
March 10, 2013 02:41AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.