KenBrace Posted February 19, 2015 Share Posted February 19, 2015 (edited) This tutorial will give a basic overview of how to retrieve information from a MySQL database. Let's say you have a database table entitled "users". This table has five fields: 1. ID 2. Username 3. Email 4. Password 5. Gender There is an entry in this table with the following values: 1. 1 2. Johnson 3. john_d@gmail.com 4. df6dd8d8f7df8dd8f7d8f7d8fdf7df6d (encrypted password) 5. Male Let's further suggest that you wish to retrieve this user and his information from the database to use it in some way (maybe display on his profile or send him an email). This is how you would go about doing it. PHP File <?php include_once("conn.php"); //include your database connection file $user = $_GET['user']; //retrieve the name of the user you wish to search via the get method. However you can get the username any way you like. I'm just doing it this way for the tutorial. $fetch_user = "SELECT * FROM users WHERE username='$user'"; //this var holds the command for fetching all fields from the 'users' table where the username is equal to the '$user' variable $query_user = mysqli_query($conn, $fetch_user); //initiate the query and specify both the connection and command if(!$query_user){ //check for an error with the query and echo error message if it fails echo "There was an error retrieving the user information!"; exit(); } ?> Edited February 19, 2015 by KenBrace 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.