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 } ?> 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 Quote 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 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]" 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 ??? 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. 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 Quote still no information appeared ??? Ok, well I am assuming that your GET[username] variable works? What happens when you echo out $b?? 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 Quote 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 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']; 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>'; 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 Quote 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 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']"; 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 Quote <?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 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? 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 Quote 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 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 Quote What errors? sorry i cant remember so many replys to this post! 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 Quote Quote 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 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 Quote Quote Quote 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 /> Quote 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 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 Quote 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 https://forums.phpfreaks.com/topic/145965-viewing-a-profile/#findComment-766356 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.