redgunner2 Posted October 25, 2015 Share Posted October 25, 2015 (edited) 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 October 25, 2015 by redgunner2 Quote Link to comment Share on other sites More sharing options...
benanamen Posted October 25, 2015 Share Posted October 25, 2015 (edited) 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 October 25, 2015 by benanamen Quote Link to comment Share on other sites More sharing options...
redgunner2 Posted October 25, 2015 Author Share Posted October 25, 2015 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. Quote Link to comment Share on other sites More sharing options...
benanamen Posted October 25, 2015 Share Posted October 25, 2015 (edited) 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 October 25, 2015 by benanamen Quote Link to comment Share on other sites More sharing options...
redgunner2 Posted October 25, 2015 Author Share Posted October 25, 2015 Already have that session_start - I posted a snippet not my full code... I'm sure you are quite helpful and knowledgeable but from a new member on the forum it seems difficult to see... Quote Link to comment Share on other sites More sharing options...
benanamen Posted October 25, 2015 Share Posted October 25, 2015 Ok, lets go with this: // What needs to go here? Again, if you go to the tutorial I posted you will have your answer. If you cannot at least do that much I don't think you are going to get much help from anyone here. We are here to help you with your code, not write it for you. Quote Link to comment Share on other sites More sharing options...
maxxd Posted October 26, 2015 Share Posted October 26, 2015 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.