Quantcast
Channel: MySQL Forums - PHP
Viewing all articles
Browse latest Browse all 938

How to set Dynamic WHERE CONDITIONS to show customer rows depending on Login using PHP? (3 replies)

$
0
0
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!!!!

Viewing all articles
Browse latest Browse all 938

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>