Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

Yesterday I have a question, just this unanswered.

I have a php login and register script. When the users register they get in the database is automatically assigned an ID (auto-increment).

This ID will in another table linked to a virtual machine (see Account ID: http://i47.tinypic.com/2gtr8g1.png).

Now I want in an HTML form's data show that virtual machine. This should be done by account by selecting the account_ID.

Could someone explain to me how to do?

According to me: SELECT * FROM .. and then I do not know anymore. It is not a fixed value for ID, ​​since the ID is different per user.

Here you see the account table: http://i50.tinypic.com/2cgg75g.png

The tables I have are: Account(Here came the registered users with an auto-increment ID(account_id)) VM_Instance(Here stay the virtual machine details etc. These I would display in an HTML form which sorted on account_id)

I don't have code, I don't know how to work with this.. And I want a HTML Form that is filled with the table data I choose. But the data is per account different

share|improve this question
1  
This is the same question as yesterday, isn't it? Please take care to ask a better question to have a chance to keep it open. Don't show us your tables by pictures for instance. Tell us what you have (what table definitions etc), what code you have (what php variable are you talking about), what outcome you expect, and maybe where you are going wrong. or something. – Nanne Jan 17 '13 at 9:16
    
    
please, change your question body, don't add it as a comment. – Nanne Jan 17 '13 at 9:32

3 Answers 3

If you have defined your 'login' column as unique, then you could retrieve your id like this:

select id from users where login='blabla';

You could also use the mysql_insert_id function, which gives you the last generated ID.

share|improve this answer
    
But how see the PHP script automatic the loginname? – haassiej Jan 17 '13 at 9:27
1  
No offense, but it seems you are relatively new to PHP programming. Perhaps you should start reading books or tutorials to improve your PHP skills, then you will know how to "remember" your login between the register page and your next page. – Bastien Jansen Jan 17 '13 at 9:31
    
Then I have bad news for you, it is not in SO's policy to give you your homework solution (see meta.stackexchange.com/questions/18242/…). Not having the time to learn a language when you have to use it to write code is not a solution, IMHO. – Bastien Jansen Jan 17 '13 at 10:03

Hope this is where you had problems.

$id = 1;
$name = 'admin';

$query = "SELECT * FROM `table_name` WHERE id = {$id} "; // for numbers
$query = "SELECT * FROM `table_name` WHERE account_name = '{$name}' "; // for strings

$query = "SELECT * FROM `table_name` WHERE id = '".$name."'; // this is another way of doing it by concatenating strings.

mysqli_query($conn, $query); // and so on
share|improve this answer
    
But you say the variable id = 1. But the variable is different per account. You will see in the second printscreen. – haassiej Jan 17 '13 at 9:18

Mmmm... from what i understand, when user logs in you need to get his id

SELECT id FROM account WHERE account_name = "<account name of user>"

This will get you the id, next you need information from vm table (as i understand from your question). So using the id you just do

SELECT * FROM vm_instance WHERE account_id = <id from previous query>
share|improve this answer
    
But how do the PHP script see the username? Dynamically? – haassiej Jan 17 '13 at 9:28
    
No, you have to request it from user (when he logs in just store it somewhere), otherwise you don't know who's accessing your page =) – Darvex Jan 17 '13 at 9:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.