Jump to content

[SOLVED] How to get information from a MYSQL data base - e.g: show user login information


Recommended Posts

Hey, i want to get and display the users login name on my members page. But i can't seem to get the data from the database. The data is in a database named Trinity_clients and in a table called members. Any help will be greatly appreciated thanks!

 

<?php
   	$dbh=mysql_connect ("localhost", "trinity_admin",
"*MYPASSWORD*) or die('Cannot connect to the database because: ' . mysql_error());
mysql_select_db ("trinity_clients");
   
   $id = ("GET * FROM `members` username");
   
echo $id;

?>

 

Any help will be greatly appreciated thanks!

You first need to readup on your MYSQL sytax. Use SELECT to retrieve data from a table. To run a query in PHP use the mysql_query function, followed by mysql_fetch_assoc

 

You'll find helpful tutorials over at http://www.php-mysql-tutorial.com/

you need to use mysql_query() to query a mysql database.  You also need the members id from a variable such as a  session var to display the login info.

 

http://us2.php.net/manual/en/function.mysql-query.php

 

<?php
$query = "SELECT `username` FROM `members` WHERE `id` = '{$_SESSION['id']}'";
$run = mysql_query($query);
if($run){
 $arr = mysql_fetch_assoc($run);
 $id = $arr['id'];
}else{
  echo mysql_error();
}
?>

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.