Jump to content

Viewing a profile


chrisC

Recommended Posts

Im having problems displaying the fields of a persons profile that someone is friends with on the database.

When I click the persons profile it comes up with the following

 

Name:

birthday:

interests:

 

No information appears why is this???

 

<?php

session_start();

if ( !isset ($_SESSION["gatekeeper"]))

{

    echo "Sorry, You are not logged in please try again! <a href=\"home.html\">login</a> ";

}

else

{

 

?>

 

<?php

$a = $_SESSION["gatekeeper"];

$b = $_GET["username"];

echo "You are viewing $b profile:";

 

$conn = mysql_connect("localhost", "ccheckley", "4aPRaJew");

mysql_select_db("ccheckley");

 

$result = mysql_query("SELECT name FROM users WHERE username='$b'");

$row = mysql_fetch_array($result);

echo "<br />name: $row[name]";

 

$result2 = mysql_query("SELECT username FROM users WHERE username='$b'");

$row = mysql_fetch_array($result2);

echo "<br />username: $row[username]";

 

$result3 = mysql_query("SELECT birthday FROM users WHERE username='$b'");

$row = mysql_fetch_array($result3);

echo "<br />birthday: $row[birthday]";

 

$result4 = mysql_query("SELECT interests FROM users WHERE username='$b'");

$row = mysql_fetch_array($result4);

echo "<br />interests: $row[interests]";

 

 

 

?>

 

 

<?php

}

?>

Link to comment
Share on other sites

Im having problems displaying the fields of a persons profile that someone is friends with on the database.

When I click the persons profile it comes up with the following

 

Name:

birthday:

interests:

 

No information appears why is this???

 

<?php

session_start();

if ( !isset ($_SESSION["gatekeeper"]))

{

    echo "Sorry, You are not logged in please try again! <a href=\"home.html\">login</a> ";

}

else

{

 

?>

 

<?php

$a = $_SESSION["gatekeeper"];

$b = $_GET["username"];

echo "You are viewing $b profile:";

 

$conn = mysql_connect("localhost", "ccheckley", "4aPRaJew");

mysql_select_db("ccheckley");

 

$result = mysql_query("SELECT name FROM users WHERE username='$b'");

$row = mysql_fetch_array($result);

echo "<br />name: $row[name]";

 

$result2 = mysql_query("SELECT username FROM users WHERE username='$b'");

$row = mysql_fetch_array($result2);

echo "<br />username: $row[username]";

 

$result3 = mysql_query("SELECT birthday FROM users WHERE username='$b'");

$row = mysql_fetch_array($result3);

echo "<br />birthday: $row[birthday]";

 

$result4 = mysql_query("SELECT interests FROM users WHERE username='$b'");

$row = mysql_fetch_array($result4);

echo "<br />interests: $row[interests]";

 

 

 

?>

 

 

<?php

}

?>

 

Your $row's are calling from the first query, not each individual query...

 

 

 

Link to comment
Share on other sites

Should be:

 

 

$result = mysql_query("SELECT name FROM users WHERE username='$b'");
$row = mysql_fetch_array($result);
echo "<br />name: $row[name]";

$result2 = mysql_query("SELECT username FROM users WHERE username='$b'");
$row2 = mysql_fetch_array($result2);
echo "<br />username: $row2[username]";

$result3 = mysql_query("SELECT birthday FROM users WHERE username='$b'");
$row3 = mysql_fetch_array($result3);
echo "<br />birthday: $row3[birthday]";

$result4 = mysql_query("SELECT interests FROM users WHERE username='$b'");
$row4 = mysql_fetch_array($result4);
echo "<br />interests: $row4[interests]"

Link to comment
Share on other sites

Possibly an easier way with less sql:

$result = mysql_query("SELECT name, username, interests, birthday FROM users WHERE username='$b'");

$row = mysql_fetch_array($result);

echo "<br />name: $row['name']";

echo "<br />name: $row['username']";

echo "<br />name: $row['birthday']";

echo "<br />name: $row['interests']";

 

NOTE the single quotes around your fieldnames following the row.

Link to comment
Share on other sites

Possibly an easier way with less sql:

$result = mysql_query("SELECT name, username, interests, birthday FROM users WHERE username='$b'");

$row = mysql_fetch_array($result);

echo "<br />name: $row['name']";

echo "<br />name: $row['username']";

echo "<br />name: $row['birthday']";

echo "<br />name: $row['interests']";

 

This also didnt show up right :S

 

NOTE the single quotes around your fieldnames following the row.

Link to comment
Share on other sites

Try

$result = mysql_query("SELECT name, username, interests, birthday FROM users WHERE username='$b'");

$row = mysql_fetch_array($result);

echo '<br />'.'name: '.$row['name'];

echo '<br />'.'name: '.$row['username'];

echo '<br />'.'name: '.$row['birthday'];

echo '<br />'.'name: '.$row['interests'];

Link to comment
Share on other sites

<?php
session_start();
if(!isset ($_SESSION["gatekeeper"]))
{
    echo "Sorry, You are not logged in please try again! <a href=\"home.html\">login</a> ";
}
else
{

?>

<?php
$a = $_SESSION["gatekeeper"];
$b = $_GET["username"];
echo "You are viewing $b profile:";

$conn = mysql_connect("localhost", "*****", "******"); // dont forget to change password 
mysql_select_db("ccheckley");

$result = mysql_query("SELECT `name`,`birthday`, `interests` FROM `users` WHERE `username`='$b' LIMIT 1") or die(mysql_error());
$row = mysql_fetch_array($result);
echo '<br />name: ',$row['name'];
echo '<br />username: ',$b;
echo '<br />birthday: ',$row['birthday'];
echo '<br />interests: ',$row['interests'];

?>


<?php
}
?>

 

A few things I noticed... You can condense that query into 1 query, and you can use LIMIT, since you were only needing one row. Also, no need to call username, if $b is username ;)

 

If that doesn't work:

find:

$row = mysql_fetch_array($result);

replace with:

$row = mysql_fetch_array($result);
echo '<pre>'; print_r($row); echo '</pre>';

Link to comment
Share on other sites

Try

$result = mysql_query("SELECT name, username, interests, birthday FROM users WHERE username='$b'");

$row = mysql_fetch_array($result);

echo '<br />'.'name: '.$row['name'];

echo '<br />'.'name: '.$row['username'];

echo '<br />'.'name: '.$row['birthday'];

echo '<br />'.'name: '.$row['interests'];

 

:'( nope, im soo confused???

Link to comment
Share on other sites

<?php
session_start();
if(!isset ($_SESSION["gatekeeper"]))
{
    echo "Sorry, You are not logged in please try again! <a href=\"home.html\">login</a> ";
}
else
{

?>

<?php
$a = $_SESSION["gatekeeper"];
$b = $_GET["username"];
echo "You are viewing $b profile:";

$conn = mysql_connect("localhost", "*****", "******"); // dont forget to change password 
mysql_select_db("ccheckley");

$result = mysql_query("SELECT `name`,`birthday`, `interests` FROM `users` WHERE `username`='$b' LIMIT 1") or die(mysql_error());
$row = mysql_fetch_array($result);
echo '<br />name: ',$row['name'];
echo '<br />username: ',$b;
echo '<br />birthday: ',$row['birthday'];
echo '<br />interests: ',$row['interests'];

?>


<?php
}
?>

 

A few things I noticed... You can condense that query into 1 query, and you can use LIMIT, since you were only needing one row. Also, no need to call username, if $b is username ;)

 

If that doesn't work:

find:

$row = mysql_fetch_array($result);

replace with:

$row = mysql_fetch_array($result);
echo '<pre>'; print_r($row); echo '</pre>';

 

this was what I was going for, but this came up with a whole load of errors

Link to comment
Share on other sites

Do this:

 

 

 

$result = mysql_query("SELECT name, username, interests, birthday FROM users WHERE username='".$b."' ");
$row = mysql_fetch_array($result);
echo "<br />name: $row['name']";
echo "<br />name: $row['username']";
echo "<br />name: $row['birthday']";
echo "<br />name: $row['interests']";

 

i got an error on this line echo "<br />name: $row['name']";

 

Link to comment
Share on other sites

Do this:

 

 

 

$result = mysql_query("SELECT name, username, interests, birthday FROM users WHERE username='".$b."' ");
$row = mysql_fetch_array($result);
echo "<br />name: $row['name']";
echo "<br />name: $row['username']";
echo "<br />name: $row['birthday']";
echo "<br />name: $row['interests']";

 

i got an error on this line echo "<br />name: $row['name']";

 

 

Why are you putting a slash (/) in your BR tag?

Link to comment
Share on other sites

Do this:

 

 

 

$result = mysql_query("SELECT name, username, interests, birthday FROM users WHERE username='".$b."' ");
$row = mysql_fetch_array($result);
echo "<br />name: $row['name']";
echo "<br />name: $row['username']";
echo "<br />name: $row['birthday']";
echo "<br />name: $row['interests']";

 

i got an error on this line echo "<br />name: $row['name']";

 

 

Why are you putting a slash (/) in your BR tag?

@allwork:

In xhtml you have to close the tags, thus requiring a />

C.2. Empty Elements

 

Include a space before the trailing / and > of empty elements, e.g. <br />, <hr /> and <img src="karen.jpg" alt="Karen" />. Also, use the minimized tag syntax for empty elements, e.g. <br />, as the alternative syntax <br></br> allowed by XML gives uncertain results in many existing user agents.

 

 

@OP: we're pretty much giving you the same code. Do you get any errors when you run:

<?php
session_start();
if(!isset ($_SESSION["gatekeeper"]))
{
    echo "Sorry, You are not logged in please try again! <a href=\"home.html\">login</a> ";
}
else
{

?>

<?php
$a = $_SESSION["gatekeeper"];
$b = $_GET["username"];
echo "You are viewing $b profile:";

$conn = mysql_connect("localhost", "*****", "******"); // dont forget to change password 
mysql_select_db("ccheckley");

$result = mysql_query("SELECT `name`,`birthday`, `interests` FROM `users` WHERE `username`='$b' LIMIT 1") or die(mysql_error());
$row = mysql_fetch_array($result);
echo '<br />name: ',$row['name'];
echo '<br />username: ',$b;
echo '<br />birthday: ',$row['birthday'];
echo '<br />interests: ',$row['interests'];

?>


<?php
}
?>

Link to comment
Share on other sites

C.2. Empty Elements

 

Include a space before the trailing / and > of empty elements, e.g. <br />, <hr /> and <img src="karen.jpg" alt="Karen" />. Also, use the minimized tag syntax for empty elements, e.g. <br />, as the alternative syntax <br></br> allowed by XML gives uncertain results in many existing user agents.

 

 

 

HMMM....you learn something new everyday!

Link to comment
Share on other sites

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.