473,387 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to set Dynamic WHERE showing customer rows depend on customer_ID using PHP?

132 100+
Hi all once again!!

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
  1. <html>
  2. <head>
  3.   <meta content="text/html; charset=ISO-8859-1"
  4.  http-equiv="content-type">
  5.   <title></title>
  6. </head>
  7. <body>
  8. <form target="_self" enctype="text/plain" method="post"
  9.  action="Results.php" name="Login_Form"><label>User
  10. name</label> &nbsp; 
  11. <label>Password<br> <br> </label><input name="UserName" value="User Name">
  12. &nbsp;<input name="Password" value="Password"
  13.  type="password"><br>
  14.   <br>
  15. &nbsp; 
  16. &nbsp; &nbsp; <input name="Submit" value="submit"
  17.  type="submit"><br>
  18.   <br>
  19. </form>
  20. </body>
  21. </html>
  22.  
  23.  
2. Results.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $dbhost = 'localhost:3306';
  3. $dbuser = 'root';
  4. $dbpass = 'rootpassword';
  5. $conn = mysql_connect($dbhost, $dbuser, $dbpass);
  6. if(! $conn )
  7. {
  8.   die('Could not connect: ' . mysql_error());
  9. }
  10. $sql = 'Customer_ID, Customer_FullName, OrderID, OrderDetails,submission_date, Customer_LoginID WHERE .....?';
  11.  
  12. mysql_select_db('tblCustomers');
  13. $retval = mysql_query( $sql, $conn );
  14. if(! $retval )
  15. {
  16.   die('Could not get data: ' . mysql_error());
  17. }
  18. while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
  19. {
  20.     echo "Customer_ID :{$row['Customer_ID']}  <br> ".
  21.          "Full Name: {$row['Customer_FullName']} <br> ".
  22.          "Order Details: {$row['OrderDetails']} <br> ".
  23.          "Date : {$row['submission_date']} <br> ".
  24.          "--------------------------------<br>";
  25. echo "Fetched data successfully\n";
  26. mysql_close($conn);
  27. ?>
  28.  
  29.  
Now how to fetch specific data due to specific customer? Any hint would be highly appreciated
Please!!!!
Mar 10 '13 #1
3 1953
Rabbit
12,516 Expert Mod 8TB
You can use the where condition in your select query to filter for the results you're looking for.
Mar 10 '13 #2
Mr Key
132 100+
Is better you leave the question unanswered rather than typing one line blablaaa.
I know very well how to write WHERE CONDITION, the issue is to capture the input from one login form to SQL!
Please the other time read first before u respond
Mar 12 '13 #3
r035198x
13,262 8TB
It's more of a PHP question than a MYSQL one then. I would suggest putting the userId in the session when the user logs in though rather than submitting with every request to your results page. Then you look it up from the session using $_SESSION['userId'] syntax and append it to the where clause if your table structure supports that.
That way you can always filter anything from anywhere based on that userId.
You can read more about session variables here: http://www.w3schools.com/php/php_sessions.asp
Mar 12 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: archana | last post by:
Hi all, I am having one dataset in which i am taking data from database. Then in my application i am creating one new column into datatable of that dataset and assigned one default value for...
1
by: Nazish | last post by:
I want to create a dynamic rows , set rowid as first cell value then traverse all rows generated if row exists update dat row othewise craete new row
1
by: girishlc | last post by:
Hi All, Can anybody look into this below query? I’m running these below queries on Oracle SQL developer. SELECT * FROM BATCH.ITEM@SCPOREADDB WHERE ITEM LIKE '%82128%' ...
0
by: ZSvedic | last post by:
Hi all, I need to display DataRows with RowState.Deleted inside DataGridView, in a way that such rows have strikethrough font. Here is the screenshot how it should look like:...
3
by: aashishn86 | last post by:
i am using this function to add rows dynamically function addRow() { var tbl = document.getElementById('applications'); var lastRow = tbl.rows.length; // if there's no header row in...
0
by: ebernon | last post by:
The Dynamic deletion of Rows and Columns within a program is frequently desired but often hard to obtain. The Help files for VB-6 contained within Excel 2002 (XP) don’t always provide the help you...
1
by: ronakinuk | last post by:
how to insert multiple rows in excel using vba how to insert multiple rows in excel using vba how to insert multiple rows in excel using vba
1
by: santhanalakshmi | last post by:
Hi, I uploaded the excel and the data is successfully inserted to the database, by submitting the "submit button" using php script. There is an final stage for me to do is the validation of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.