Hey Daniweb, can somebody explain to my how to call a value from my database after i logged in?
Like i log in with the username and password, then i want on my member page to show what email this user has or any other thing from the database.
What code should i use?

Recommended Answers

All 7 Replies

Thanks that helped :)

no problem, that was the first thing i ever read :)

Btw if others need the answer code then here it is :

<?php
session_start();
$userid = $_SESSION['userid'];
$username = $_SESSION['username'];
?>
<html>
<head>
</head>

<body>
<?php
	if($username && $userid) {
		require("./your db connection.php");
 $query="SELECT * FROM users WHERE username='$username'";
 $result=mysql_query($query);

 $num=mysql_numrows($result);

 mysql_close();

 echo "<b><centerYour member screen</center></b><br><br>";

 $i=0;
 while ($i < $num) {

 $username=mysql_result($result,$i,"username");
 $email=mysql_result($result,$i,"email");
 $point=mysql_result($result,$i,"point");
 $clan=mysql_result($result,$i,"clan");
 $secretquestionanswer=mysql_result($result,$i,"secretquestionanswer");
 $secretquestion=mysql_result($result,$i,"secretquestion");


 echo "<b>username: $username </b>
 <br>email: $email
 <br>point: $point
 <br>clan: $clan
 <br>secretquestion answer: $secretquestionanswer
 <br>secretquestion: $secretquestion<br><br><hr><br>";

 $i++;
 }
}
else 
	echo "memberscreen did not worked";

$login = "<form method='link' action='./logout.php'>
 <input type='submit' value='logout'>
 </form>";
echo $login; 	
 ?>

</body>
</html>

If its not working for you then its course im using it with a login system. So the php know what the username is.

Member Avatar for diafol
$query="SELECT * FROM users WHERE username='$username'";
 $result=mysql_query($query);
 
 $num=mysql_numrows($result);
 
 mysql_close();
 
 echo "<b><centerYour member screen</center></b><br><br>";
 
 $i=0;
 while ($i < $num) {
 
 $username=mysql_result($result,$i,"username");
 $email=mysql_result($result,$i,"email");
 $point=mysql_result($result,$i,"point");
 $clan=mysql_result($result,$i,"clan");
 $secretquestionanswer=mysql_result($result,$i,"secretquestionanswer");
 $secretquestion=mysql_result($result,$i,"secretquestion");
 
 
 echo "<b>username: $username </b>
 <br>email: $email
 <br>point: $point
 <br>clan: $clan
 <br>secretquestion answer: $secretquestionanswer
 <br>secretquestion: $secretquestion<br><br><hr><br>";
 
 $i++;
 }

Looks far too slow. Try:

$result=mysql_query("SELECT * FROM users WHERE username='$username'");
 $output = "";
 if(mysql_num_rows($result)>0){
   while($d = mysql_fetch_assoc($result)){
      $output .= "<strong>username: {$d['username']}</strong>
      <br />email: {$d['email']}
      <br />point: {$d['point']}
      <br />clan: {$d['clan']}
      <br />secretquestion answer: {$d['secretquestionanswer']}
      <br />secretquestion: {$d['secretquestion']}<br /><br /><hr /><br />";
   }
 }

 echo "<p style="text-align:center;"><strong>Your member screen</strong></p><br />$output";

Well it did worked when i removed the p style. But why is this faster than the other code?

Member Avatar for diafol

http://php.net/manual/en/function.mysql-result.php
states:

"When working on large result sets, you should consider using one of the functions that fetch an entire row (specified below). As these functions return the contents of multiple cells in one function call, they're MUCH quicker than mysql_result(). Also, note that specifying a numeric offset for the field argument is much quicker than specifying a fieldname or tablename.fieldname argument."

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.