chrisC Posted February 19, 2009 Share Posted February 19, 2009 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/145965-viewing-a-profile/ Share on other sites More sharing options...
allworknoplay Posted February 19, 2009 Share Posted February 19, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/145965-viewing-a-profile/#findComment-766318 Share on other sites More sharing options...
allworknoplay Posted February 19, 2009 Share Posted February 19, 2009 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]" Quote Link to comment https://forums.phpfreaks.com/topic/145965-viewing-a-profile/#findComment-766319 Share on other sites More sharing options...
chrisC Posted February 19, 2009 Author Share Posted February 19, 2009 still no information appeared ??? Quote Link to comment https://forums.phpfreaks.com/topic/145965-viewing-a-profile/#findComment-766325 Share on other sites More sharing options...
Drewser33 Posted February 19, 2009 Share Posted February 19, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/145965-viewing-a-profile/#findComment-766327 Share on other sites More sharing options...
allworknoplay Posted February 19, 2009 Share Posted February 19, 2009 still no information appeared ??? Ok, well I am assuming that your GET[username] variable works? What happens when you echo out $b?? Quote Link to comment https://forums.phpfreaks.com/topic/145965-viewing-a-profile/#findComment-766329 Share on other sites More sharing options...
chrisC Posted February 19, 2009 Author Share Posted February 19, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/145965-viewing-a-profile/#findComment-766334 Share on other sites More sharing options...
Drewser33 Posted February 19, 2009 Share Posted February 19, 2009 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']; Quote Link to comment https://forums.phpfreaks.com/topic/145965-viewing-a-profile/#findComment-766337 Share on other sites More sharing options...
Philip Posted February 19, 2009 Share Posted February 19, 2009 <?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>'; Quote Link to comment https://forums.phpfreaks.com/topic/145965-viewing-a-profile/#findComment-766340 Share on other sites More sharing options...
chrisC Posted February 19, 2009 Author Share Posted February 19, 2009 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??? Quote Link to comment https://forums.phpfreaks.com/topic/145965-viewing-a-profile/#findComment-766341 Share on other sites More sharing options...
allworknoplay Posted February 19, 2009 Share Posted February 19, 2009 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']"; Quote Link to comment https://forums.phpfreaks.com/topic/145965-viewing-a-profile/#findComment-766344 Share on other sites More sharing options...
chrisC Posted February 19, 2009 Author Share Posted February 19, 2009 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/145965-viewing-a-profile/#findComment-766346 Share on other sites More sharing options...
Philip Posted February 19, 2009 Share Posted February 19, 2009 What errors? Quote Link to comment https://forums.phpfreaks.com/topic/145965-viewing-a-profile/#findComment-766348 Share on other sites More sharing options...
chrisC Posted February 19, 2009 Author Share Posted February 19, 2009 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']"; Quote Link to comment https://forums.phpfreaks.com/topic/145965-viewing-a-profile/#findComment-766351 Share on other sites More sharing options...
chrisC Posted February 19, 2009 Author Share Posted February 19, 2009 What errors? sorry i cant remember so many replys to this post! Quote Link to comment https://forums.phpfreaks.com/topic/145965-viewing-a-profile/#findComment-766352 Share on other sites More sharing options...
allworknoplay Posted February 19, 2009 Share Posted February 19, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/145965-viewing-a-profile/#findComment-766353 Share on other sites More sharing options...
Philip Posted February 19, 2009 Share Posted February 19, 2009 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/145965-viewing-a-profile/#findComment-766354 Share on other sites More sharing options...
allworknoplay Posted February 19, 2009 Share Posted February 19, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/145965-viewing-a-profile/#findComment-766356 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.