Lol, yeah this one is a terror.
Ok so lets cut out all the unnecessary code, I guess you are familiar with how it should work by now. Basically we just want to get a users id from the table. Try this code on your server, don't forget to change the username, try it first with something that is in the db table;
Code: Select all
<?php
include('Connections/recommendingpeople.php');
// Assign the username !!!!!CHANGE THIS TO ONE THAT IS IN THE TABLE!!!!!
// If it is not in the table you should get to where I put ####!!!#### that
$username = "Username";
$query= "SELECT userid FROM rsusername WHERE username='$username';";
$result = mysql_query($query);
$numRows = mysql_num_rows($result);
if ($numRows) {
if ($numRows == 1) {
$array = mysql_fetch_array($result, MYSQL_ASSOC);
$userid = $array['userid'];
echo $userid;
} elseif ($numRows > 1) {
echo "Lots of rows were returned";
} else {
echo "No rows were returned and we are in the if statement, actually we should never reach here.";
}
} else {
// ####!!!####
echo "No rows were returned";
}
?>
I have tried an equivalent, and it worked 100%. For reference the code I used is;
Code: Select all
<?php
include('connecttodatabase.php');
// Assign the username !!!!!CHANGE THIS TO ONE THAT IS IN THE TABLE!!!!!
// If it is not in the table you should get to where I put ####!!!#### that
$username = "Neilos";
$query= "SELECT userid FROM users WHERE username='$username';";
$result = mysql_query($query);
$numRows = mysql_num_rows($result);
if ($numRows) {
if ($numRows == 1) {
$array = mysql_fetch_array($result, MYSQL_ASSOC);
$userid = $array['userid'];
echo $userid;
} elseif ($numRows > 1) {
echo "Lots of rows were returned";
} else {
echo "No rows were returned and we are in the if statement, actually we should never reach here.";
}
} else {
// ####!!!####
echo "No rows were returned";
}
?>
I tried it with no username that matched, one username that matched and two usernames that matched, all parts of the code were functioning correctly with no errors or warnings.
If this doesn't work then I suggest checking all the table names, table field names, usernames etc... checking that they are all what you would expect, especially check for whitespace, we could actually of stripped this from any strings just to make sure but we didn't, maybe we will later lol.
I just had a thought also. When trying to access session variables, you have been checking that they are set first haven't you? I've just been assuming that they were set. However the code I want you to try now has no session so that'll not be a problem.
Neilos wrote:
Also I would like to reiterate a question...
Neilos wrote:And line 16 is blank?!!? Are you posting the code for the php file in the error, ie the content of profilesummary.php?
Sorry I didn't explain this very well. What I mean is are you posting the code that is contained in the .php file that the error is pointing to? ie I wanted to make sure that the code I was seeing was the code from the file profilesummary.php. The reason is that it is weird that the error points to blank lines.
What are you writing the code in? notepad++? an IDE? And where is your development environment, is it an apache server on your pc or a server on the net?