Jump to content

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


dr.maju

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();
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.