im having problems in PHP with selecting Infomation from a database where username is equal to $myusername
I can get it to echo the username using sessions from the login page to the logged in page.
But I want to be able to select things like 'bio' and 'email' from that database and put them into variables called $bio and $email so i can echo them.
This is what the database looks like:
You should connect to your database and then fetch the row like this:
// DATABASE INFORMATION $server = 'localhost'; $database = 'DATABASE'; $dbuser = 'DATABASE_USERNAME'; $dbpassword = 'DATABASE_PASSWORD'; //CONNECT TO DATABASE $connect = mysql_connect("$server", "$dbuser", "$dbpassword") OR die(mysql_error()); mysql_select_db("$database", $connect); //ALWAYS ESCAPE STRINGS IF YOU HAVE RECEIVED THEM FROM USERS $safe_username = mysql_real_escape_string($X); //FIND AND GET THE ROW $getit = mysql_query("SELECT * FROM table_name WHERE username='$safe_username'", $connect); $row = mysql_fetch_array($getit); //YOUR NEEDED VALUES $bio = $row['bio']; $bio = $row['email'];
Dont Use Plain Text for Passwords, Always hash the passwords with a salt
I used MYSQL_QUERY for your code because i don't know PDO or Mysqli, Escaping in MYSQL is good enought but Consider Using PDO or Mysqli , as i don't know them i can't write the code with them for you