PHP problem (please help soon!)

igames

New Member
Messages
34
Reaction score
0
Points
0
hey i have some php expirence but not that much and im wondering if someone could help me here. the problem is that i need to display a user information so he/she can edit it if needed and ect. so i am trying to call a session in a mysql query. i dont know if this will work (so far it hasnt) and i need help. so here is the code

PHP:
$query="SELECT * FROM users WHERE username = ". $_SESSION['myusername'] ."; ";

$result=mysql_query($query) or die(mysql_error());

$num=mysql_numrows($result);

echo "<b><center>Account Info</center></b><br><br>";

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

$name=mysql_result($result,$i,"name");
$username=mysql_result($result,$i,"username");
$email=mysql_result($result,$i,"email");

echo "Name:<br><b>$name</b><br><br>Username:<br>$username<br><br>E-Mail:<br>$email<br><hr><br>";

$i++;
}
?>


anyone tell me what im doing wrong?
thanks in advance

i forgot that i wanted to tell you i have the connect to the database but i just didnt feel like posting it
Edit:
i am sorry that i have posted this form but i have now figured it out.:biggrin:
 
Last edited:

Aravinthan

New Member
Messages
68
Reaction score
0
Points
0
hey i have some php expirence but not that much and im wondering if someone could help me here. the problem is that i need to display a user information so he/she can edit it if needed and ect. so i am trying to call a session in a mysql query. i dont know if this will work (so far it hasnt) and i need help. so here is the code

PHP:
$query="SELECT * FROM users WHERE username = ". $_SESSION['myusername'] ."; ";
 
$result=mysql_query($query) or die(mysql_error());
 
$num=mysql_numrows($result);
 
echo "<b><center>Account Info</center></b><br><br>";
 
$i=0;
while ($i < $num) {
 
$name=mysql_result($result,$i,"name");
$username=mysql_result($result,$i,"username");
$email=mysql_result($result,$i,"email");
 
echo "Name:<br><b>$name</b><br><br>Username:<br>$username<br><br>E-Mail:<br>$email<br><hr><br>";
 
$i++;
}
?>


anyone tell me what im doing wrong?
thanks in advance

i forgot that i wanted to tell you i have the connect to the database but i just didnt feel like posting it
Edit:
i am sorry that i have posted this form but i have now figured it out.:biggrin:

Is it a only a part of the whole code?
Because you need to give the username, password and localhost. If its a part, you dont need use the session:
mysql_query("SELECT * FROM users where username="myusername" )
or die("error querying database");
It should work...... because i need the whole part
 

Myokram

New Member
Messages
30
Reaction score
0
Points
0
If $_SESSION['myusername'] is a string value, then you need to 'single-quote' it:

PHP:
$query="SELECT * FROM users WHERE username = '". $_SESSION['myusername'] ."'";
Anyway, does it display any error message? What's wrong with your code?

Greetings.
 

xmakina

New Member
Messages
264
Reaction score
0
Points
0
Reply to the thread saying you've fixed it. It's very easy to miss that last line.

Also - how did you fix it?
 
Top