Jump to content

Only show Mysql data from a certain user


winmastergames

Recommended Posts

Well just to say this is different to my other post...

Im trying to find a way to get data from a certain username only like email or something. The user will login and i need it to display their email address how do i go about trying to do this I tried in mysql just as a guess didnt work but i tried typing in

mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());

it just came up with nothing but i guess it will be something like that

Link to comment
https://forums.phpfreaks.com/topic/89623-only-show-mysql-data-from-a-certain-user/
Share on other sites

Providing the data in the MySql database field `username` matches $username, this should work.

Echo $username, and match it to the `username` field in the database.

If they don't match, then there is your problem. if they do, then it is somewhere in your display code.

It still doesnt show anything if i dont have WHERE username =....blah.blah stuff it shows the Data but when i do Where username =..blah.blah stuff..... it shows nothing?? what would be wrong i did Moon-Man.net post and everything was fine but does somehow the username and let say email do they have to be connected or something to be read??

$email = mysql_query("SELECT email FROM users WHERE username = '" . $username . "''")or die(mysql_error());
$email = mysql_fetch_array($email);
echo "email: " . $email[0];

 

This will only output the email for one user, so if more than one person has the same username, its not going to work.

Heres the complete code

<?php 
//Defines Vars

// Connects to your Database 
mysql_connect("localhost", "root", "com12345") or die(mysql_error()); 
mysql_select_db("test") or die(mysql_error()); 

//checks cookies to make sure they are logged in 
if(isset($_COOKIE['ID_my_site'])) 
{ 
$username = $_COOKIE['ID_my_site']; 
$pass = $_COOKIE['Key_my_site']; 
$check = mysql_query("SELECT * FROM users WHERE username = '{$username}'")or die(mysql_error()); 
while($info = mysql_fetch_array( $check )) 
{ 

//if the cookie has the wrong password, they are taken to the login page 
if ($pass != $info['password']) 
{ header("Location: login.php"); 
} 

//otherwise they are shown the admin area	
else 
{ 
$yrwebsite = $_POST["weburl"];
echo "Website Administration<p>"; 
if (isset($_COOKIE["ID_my_site"]))
  echo "Welcome " . $_COOKIE["ID_my_site"] . " to SWD<br />";
else
  echo "Welcome guest!<br />";
echo "Your website URL is";
$sql = "SELECT * FROM users WHERE username = '$username'";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<td>".$row['weburls']."</td><br>";
}
echo "Your FTP Username is: ";
$sql = "SELECT * FROM users";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<td>".$row['ftpuser']."</td>";
}
echo "<br>";
echo "Your FTP Password is: ";
$sql = "SELECT * FROM users";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query)) {
echo "<td>".$row['ftppass']."</td>";
}
echo "<br><a href=logout.php>Logout</a>"; 
} 
} 
} 
else 

//if the cookie does not exist, they are taken to the login screen 
{	
header("Location: login.php"); 
} 
?>

 

Please try this :)

 

<?php 
//Defines Vars

// Connects to your Database 
mysql_connect("localhost", "root", "com12345") or die(mysql_error()); 
mysql_select_db("test") or die(mysql_error()); 

//checks cookies to make sure they are logged in 
if(isset($_COOKIE['ID_my_site'])){ 
$username = $_COOKIE['ID_my_site']; 
$pass = $_COOKIE['Key_my_site']; 
$check = mysql_query("SELECT * FROM users WHERE username = '{$username}'")or die(mysql_error()); 
while($info = mysql_fetch_array( $check )){ 
	//if the cookie has the wrong password, they are taken to the login page 
	if ($pass != $info['password']){
		header("Location: login.php"); 
	}else{ 
		$yrwebsite = $_POST["weburl"];
		echo "Website Administration<p>"; 
		if (isset($_COOKIE["ID_my_site"])){
		  echo "Welcome " . $_COOKIE["ID_my_site"] . " to SWD<br />";
		}else{
			echo "Welcome guest!<br />";
		}
		$sql = "SELECT * FROM users WHERE username = '$username'";
		$query = mysql_query($sql);

		while($row = mysql_fetch_array($query)) {
			echo "<td>Your website URL is: ".$row['weburls']."</td>";
			echo "<td>Your FTP Username is: ".$row['ftpuser']."</td>";
			echo "<td>Your FTP Password is: ".$row['ftppass']."</td>";
		}
		echo "<br><a href=logout.php>Logout</a>"; 
		echo "<br>";
		echo "<br>DEBUG RESULT:"
		print_r(mysql_fetch_array($query));
	} 
} 
}else{
//if the cookie does not exist, they are taken to the login screen	
header("Location: login.php"); 
} 
?>

My Mistake, forgot a ';' on line 35

 

<?php 
//Defines Vars

// Connects to your Database 
mysql_connect("localhost", "root", "com12345") or die(mysql_error()); 
mysql_select_db("test") or die(mysql_error()); 

//checks cookies to make sure they are logged in 
if(isset($_COOKIE['ID_my_site'])){ 
$username = $_COOKIE['ID_my_site']; 
$pass = $_COOKIE['Key_my_site']; 
$check = mysql_query("SELECT * FROM users WHERE username = '{$username}'")or die(mysql_error()); 
while($info = mysql_fetch_array( $check )){ 
	//if the cookie has the wrong password, they are taken to the login page 
	if ($pass != $info['password']){
		header("Location: login.php"); 
	}else{ 
		$yrwebsite = $_POST["weburl"];
		echo "Website Administration<p>"; 
		if (isset($_COOKIE["ID_my_site"])){
		  echo "Welcome " . $_COOKIE["ID_my_site"] . " to SWD<br />";
		}else{
			echo "Welcome guest!<br />";
		}
		$sql = "SELECT * FROM users WHERE username = '$username'";
		$query = mysql_query($sql);

		while($row = mysql_fetch_array($query)) {
			echo "<td>Your website URL is: ".$row['weburls']."</td>";
			echo "<td>Your FTP Username is: ".$row['ftpuser']."</td>";
			echo "<td>Your FTP Password is: ".$row['ftppass']."</td>";
		}
		echo "<br><a href=logout.php>Logout</a>"; 
		echo "<br>";
		echo "<br>DEBUG RESULT:";
		print_r(mysql_fetch_array($query));
	} 
} 
}else{
//if the cookie does not exist, they are taken to the login screen	
header("Location: login.php"); 
} 
?>

Haku, he is not trying to display the email at all, he wants the ftp username, ftp password and weburl for the specific user out of the database....

 

<?php 
//Defines Vars

// Connects to your Database 
mysql_connect("localhost", "root", "com12345") or die(mysql_error()); 
mysql_select_db("test") or die(mysql_error()); 

//checks cookies to make sure they are logged in 
if(isset($_COOKIE['ID_my_site'])){ 
$username = $_COOKIE['ID_my_site']; 
$pass = $_COOKIE['Key_my_site']; 
$check = mysql_query("SELECT * FROM users WHERE username = '{$username}'")or die(mysql_error()); 
while($info = mysql_fetch_array( $check )){ 
	//if the cookie has the wrong password, they are taken to the login page 
	if ($pass != $info['password']){
		header("Location: login.php"); 
	}else{ 
		$yrwebsite = $_POST["weburl"];
		echo "Website Administration<p>"; 
		if (isset($_COOKIE["ID_my_site"])){
		  echo "Welcome " . $_COOKIE["ID_my_site"] . " to SWD<br />";
		}else{
			echo "Welcome guest!<br />";
		}
		$sql = "SELECT * FROM users";
		$query = mysql_query($sql);
	        $result=mysql_fetch_array($query);
		while($result as $row ) {
			echo "<td>Your website URL is: ".$row['weburls']."</td>";
			echo "<td>Your FTP Username is: ".$row['ftpuser']."</td>";
			echo "<td>Your FTP Password is: ".$row['ftppass']."</td>";
		}
		echo "<br><a href=logout.php>Logout</a>"; 
		echo "<br>";
		echo "<br>DEBUG RESULT:";
                        echo "Username: " .$username ."<br>";
		print_r(mysql_fetch_array($query));
	} 
} 
}else{
//if the cookie does not exist, they are taken to the login screen	
header("Location: login.php"); 
} 
?>

 

Let me know what that outputs, I'm guessing $username isnt being set correctly

Really? Cause his first message said this:

 

Im trying to find a way to get data from a certain username only like email or something. The user will login and i need it to display their email address how do i go about trying to do this

 

Sure looks to me like he was looking to get the email address...

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.