soupy127 Posted April 21, 2010 Share Posted April 21, 2010 Hi have 2 queries, hope somebody can help. the first is how do i edit this function so that it works with my phpmyadmin database when it has no username or password? The database is called duffers. Everytime i edit it i get errors. (sorry im just learning php) function setupdb($dbuser,$pw,$dbase) { $this->dbuser=$dbuser; $this->pw=$pw; $this->dbase=$dbase; $this->db = mysql_connect('localhost',$dbuser,$pw); } and the second query is, i have my website set up with sessions, so was wandering how do i display the persons information once he has logged in. I.e i need the query to recognise the username from of the the logged in user and only display his information, here was my attempt. <?php //session start and get variable session_start(); $username = $_SESSION['username']; //connect to database $connect = mysql_connect("localhost","root","") or die ("sorry couldn't connect"); mysql_select_db("duffers") or die("couldnt connect"); $get = mysql_query("SELECT * FROM users WHERE username='$username'"); print username ='username', name = 'name', Email = 'email'; <a href='logout.php'>Logout</a>"; } else die("you must be logged in"); ?> any help would be greatly appreciated!! thanks again Link to comment https://forums.phpfreaks.com/topic/199311-need-help-yet-again-sorry-please-help/ Share on other sites More sharing options...
ScotDiddle Posted April 21, 2010 Share Posted April 21, 2010 soupy127, Here is a simple query which returns the results you are looking for... ( Different DB, and Table, but the format and concepts are correct... ) Scot L. Diddle, Richmond VA <?php Header("Cache-control: private, no-cache"); Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); Header("Pragma: no-cache"); $link = mysql_connect('localhost', 'myName', 'myPW'); if (!$link) { die('Could not connect: ' . mysql_error()); } $DB_Select = mysql_select_db('mysql'); $user = 'myName'; // This should be a valid mysql user... $sql = "SELECT * FROM user WHERE user='$user'"; $get = mysql_query($sql); while ($row = mysql_fetch_array($get)) { $username=$row['User']; } echo $username; // echos 'myName' ?> Link to comment https://forums.phpfreaks.com/topic/199311-need-help-yet-again-sorry-please-help/#findComment-1046087 Share on other sites More sharing options...
soupy127 Posted April 22, 2010 Author Share Posted April 22, 2010 Thanks alot for all your help again ! I shall try it now ! Link to comment https://forums.phpfreaks.com/topic/199311-need-help-yet-again-sorry-please-help/#findComment-1046413 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.