I'm doing a profile script, diffrent things show depending on if it's the members profile that's being showed or some other users being showed. And when it's the same user that is watching their user i get undefinied variable $content. I know what it means but i don't understand why I get it cause I thought i've done it right.
I guess that the important information is where i've placed my sql quieries and where i've placed my $content variables.
Here is my code, (taken away unnessccary information:
Code: Select all
<?php
$person2 = $_SESSION['sess_user'];
$sql2 = "SELECT * FROM members WHERE username = '{$person2}'";
$result2 = mysql_query($sql2) or die(mysql_error());
if(isset($_SERVER['QUERY_STRING'])) {
$person = substr($_SERVER['QUERY_STRING'], 1);
$sql = "SELECT * FROM members WHERE username = '{$person}'";
$result = mysql_query($sql) or die(mysql_error());
// stuff that should happen if it's someone elses profile.
} else {
function birthday ($age){
// assumes $birthdate is in YYYY-MM-DD format
list($dob_year, $dob_month, $dob_day) = explode('-', $age);
// determine current year, month, and day
$cur_year = date('Y');
$cur_month = date('m');
$cur_day = date('d');
// either past or on the birthday
if($cur_month >= $dob_month && $cur_day >= $dob_day) {
$age1 = $cur_year - $dob_year;
}
// before the birthday
else {
$age1 = $cur_year - $dob_year;
}
// and your done
return $age1;
}
function fodelsedag($age){
// assumes $birthdate is in YYYY-MM-DD format
list($dob_year, $dob_month, $dob_day) = explode('-', $age);
// determine current year, month, and day
$cur_year = date('Y');
$cur_month = date('m');
$cur_day = date('d');
// either past or on the birthday
if($cur_month == $dob_month || $cur_day == $dob_day) {
$age2 = "Det är denna användares födelsedag idag GRATTIS!";
return $age2;
}
// and your done
}
while($rad = mysql_fetch_array($result2))
{
$header = $person2;
$header .= " ";
$header .= $rad['sex'];
$header .= birthday("$age");
$age = $rad['age'];
$kon = $rad['sex'];
$content = "<table>";
$content .= "<tr>";
$content .= "<td><b><font size='4'>". $rad['username']."</b> ";
$content .= $rad['sex'] . birthday("$age") . "<br>" . "</td>";
$content .= "</tr>";
$content .= "<tr>";
$content .= "<td>";
$content .= "<br>";
if(empty($rad['picture']))
{
$content .= "<img src='images/inget-foto.jpg' width='50' height='50'>";
}
else
{
$content .= "<img src='images/". $rad['picture']."'>";
}
$content .= "<br>";
$content .= "</td></tr>";
$content .= "<tr>";
$content .= "<td width=220><b>Användarnamn:</b>".$rad['username']." </td><td width=50</td><td width=150><b>Civilstånd:</b> </td><td>".$rad['civil']."</td>";
$content .= "</tr>";
$content .= "<tr>";
$content .= "<td width=220><b>Län:</b> ".$rad['lan']."</td><td width=50></td><td width=150><b>Sexuell läggning:</b></td><td>".$rad['sexuel']."</td>";
$content .= "</tr>";
$content .= "<tr>";
$content .= "<td width=220><b>Längd:</b> ".$rad['height']."</td><td width=50></td><td width=150><b>Vikt:</b></td><td>".$rad['weight']."</td>";
$content .= "</tr>";
$content .= "<tr>";
$content .= "<td width=220><b>Ögonfärg:</b> ".$rad['eye_color']."</td><td width=50></td><td width=150><b>Hårfärg:</b></td><td>".$rad['hair_color']."</td>";
$content .= "</tr>";
$content .= "</table>";
$content .= "<table>";
$content .= "<td><br><br></td>";
$content .= "<td width=100><b>Gästbok</b></td><td width=100><b>Film Galleri</b></td><td width=100><b>Bild Galleri</b></td><td width=100><b>Gör favorit</b></td><td width=100><b>Blog</b></td>";
$content .= "</tr>";
$content .= "</table>";
}
}
?>