Jump to content

Recommended Posts

Hello,

 

I'm having some difficulty formulating  query that will allow me to retrieve the details of a specific user in the database. The user's information is stored in one table called Users and another called UserProfile. Both tables are linked by the UserID field.

 

My current query returns a Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource and my knowledge of Mysql is not great(Still learnng)

 

Here is my code:


function view_profile($Username)
{

  $conn = connect();
  $query ="SELECT Users.Firstname,Users.Surname,Users.Email,Profile.Age FROM
  Users,UserProfile WHERE  Username  = '".$Username."' AND  Users.UserID =
  UserProfile.UserID";

  $result = mysql_query($query);
  $num = mysql_numrows($result);

  mysql_close();

echo "<b><center>Your profile</center></b><br>";

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

$Firstname =mysql_result($result,$i,"Firstname");
$Surname=mysql_result($result,$i,"Surname");
$Email=mysql_result($result,$i,"Email");
$Age=mysql_result($result,$i,"Age");


//echo "<<br>Firstname: $Firstname<br>Surname: $Surname<br>Email: $Email<br>Password: $Password<br> <br>Age: $Age<br>";

$i++;
}
}


Link to comment
https://forums.phpfreaks.com/topic/54412-solved-mysql-query-help/
Share on other sites

I did some error checking and fixed a mistake where Profile.Age should be UserProfile.Age which removed the error message from appearing but my View_Profile function displays nothing when I test it by going to the View Profile page.

 

This query works and allows me to display the user's profile

  $query = "SELECT * FROM Users WHERE Username  = '".$Username."'"; 

  but I need to display the User's profile from both the users able and the UserProfile table.

 

$query ="SELECT Users.Firstname,Users.Surname,Users.Email,UserProfile.Age FROM
  Users,UserProfile WHERE  Username  = '".$Username."' AND  Users.UserID =
  UserProfile.UserID";

  $result = mysql_query($query);
  $num = mysql_numrows($result);

 

I'm guessing my query is wrong so I will try and work it out.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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