Jump to content

Learning how to show information from a table


redgunner2

Recommended Posts

Hello,

 

I am learning PHP and have been trying to work out what I need to do to display information on a members page.

// Create connection
$mysqli = new mysqli('localhost', 'db', 'db', 'db');
// Check connection
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
} 

$getID = $_SESSION['user_id'];
$sql = "SELECT * from users WHERE id = ($getID)";

// What needs to go here?

So for example I have a column with firstname which I would like to print back to the user

 

Any help would be appreciative...

Edited by redgunner2
Link to comment
Share on other sites

I think what you really need to do is study some tutorials. Your question is extremely basic and shows you really haven't put any effort into learning anything.

 

IMO you are not ready to start asking for help yet.

 

At least go through the following tutorial and then see if you have any questions.

 

http://www.w3schools.com/php/php_mysql_intro.asp

 

There are also numerous tutorials at code academy that will teach you all the different areas you need to know, PHP, SQL, HTML, CSS, etc

 

https://www.codecademy.com/learn

Edited by benanamen
Link to comment
Share on other sites

You can't judge that I haven't learnt anything based on me asking for help? I wanted feedback on how others would achieve this so i can compare as I am writing a script to counter XSS for a project, please do not post sarcastic comments to people looking help - After all this is a help forum and not a look down your nose forum.

Link to comment
Share on other sites

You can't judge that I haven't learnt anything based on me asking for help?

 

Based on what you asked, I absolutely can. When I say "anything", I mean anything regarding the subject you are asking about, not implying you dont know other things.

 

We are here to help. Your question clearly shows you have not studied the most basic of basics regarding your question. The fact that your throwing in $_SESSION without  session_start further shows that unless you just have not provided the entire code for the page.

 

Instead of jumping on me you could have just gone to the first tutorial I pointed you to and you would have had your answer and more.

 

If you look over all my posts you will see I am very helpful and quite knowledgeable.

Edited by benanamen
Link to comment
Share on other sites

If you're just beginning with php, I'd recommend using PDO over MySQLi. It's an easier interface to wrap your head around, and not limited to one database as MySQLi is. Basically, what you're going to want to do is create a prepared statement using the user ID stored in session, query the database using prepared statement, and echo the resulting data to the page.

 

If you're up for the learning curve, check out a templating system for the data display (for instance, Twig) - it takes some getting used to but if you're just starting to learn, you may as well learn good habits from the get-go.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.