gtrufitt Posted March 13, 2008 Share Posted March 13, 2008 Hi, I am trying to echo the first and last name of a set of people in a table. I keep gettin the error: Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in C:\Inetpub\wwwroot\padgate2\TMPmyn02xogw6.php on line 57 and before that it only echoed the first person in the table. The 'userhall' table has the columns 'id' and 'hallid' The 'hall' table has 'hallid' and 'name' <?php mysql_connect("localhost", "admin", "admin") or die("Cannot connect to DB!"); mysql_select_db("padgate") or die("Cannot select DB!"); $hall_name = $_GET['hall']; $hallid = "SELECT hallid FROM hall WHERE name = '$hall_name'"; $hi = mysql_query($hallid) or die(mysql_error()."<Br /><br /.".$hallid); // don't use your SQL statement in your error. $rowh = mysql_fetch_array($hi); $hallid2 = $rowh['hallid']; $hall = "SELECT id FROM userhall WHERE hallid = '$hallid2'"; $h = mysql_query($hall) or die(mysql_error()."<Br /><br /.".$hall); // don't use your SQL statement in your error. ?> <?php if (mysql_num_rows($h) == 0) { echo 'Apparently no one lives in ' $hall_name ' hall!' ; } else { echo 'The following people live in ' $hall_name ' Hall! </p>'; while($rowa = mysql_fetch_array($h)) { $userid = $rowa['id']; $hallmembers = "SELECT * FROM user WHERE id = '$userid'"; $m = mysql_query($hallmembers) or die(mysql_error()."<Br /><br /.".$hallmembers); // don't use your SQL statement in your error. It will let malicious users know your table structure and open it up to sql injection. $row = mysql_fetch_array($m); { echo '<a href ="userprofile.php?user='; echo $row['id']; echo '">'; echo $row['f_name']; echo ' '; echo $row['l_name'],"</a><br />\n"; } } ?>code] Any help to get this working would be great! Thanks, Gareth Quote Link to comment https://forums.phpfreaks.com/topic/95996-help-listing-users-with-while-loop/ Share on other sites More sharing options...
p2grace Posted March 13, 2008 Share Posted March 13, 2008 Which line is 57? Quote Link to comment https://forums.phpfreaks.com/topic/95996-help-listing-users-with-while-loop/#findComment-491445 Share on other sites More sharing options...
BlueSkyIS Posted March 13, 2008 Share Posted March 13, 2008 this is invalid: echo 'Apparently no one lives in ' $hall_name ' hall!' ; Quote Link to comment https://forums.phpfreaks.com/topic/95996-help-listing-users-with-while-loop/#findComment-491446 Share on other sites More sharing options...
discomatt Posted March 13, 2008 Share Posted March 13, 2008 As well as this echo 'The following people live in ' $hall_name ' Hall! </p>'; Must use . operators to combine strings. change to echo 'The following people live in ' . $hall_name . ' Hall! </p>'; Quote Link to comment https://forums.phpfreaks.com/topic/95996-help-listing-users-with-while-loop/#findComment-491448 Share on other sites More sharing options...
BlueSkyIS Posted March 13, 2008 Share Posted March 13, 2008 i totally disagree. echoing SQL is sometimes the only way to know what's wrong. sure, you can remove it after dev/test, but it is priceless during dev. Quote Link to comment https://forums.phpfreaks.com/topic/95996-help-listing-users-with-while-loop/#findComment-491449 Share on other sites More sharing options...
p2grace Posted March 13, 2008 Share Posted March 13, 2008 this is invalid: echo 'Apparently no one lives in ' $hall_name ' hall!' ; Yeup should be: <?php echo "Apparently no one lives in ' $hall_name ' hall!" ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/95996-help-listing-users-with-while-loop/#findComment-491450 Share on other sites More sharing options...
p2grace Posted March 13, 2008 Share Posted March 13, 2008 i totally disagree. echoing SQL is sometimes the only way to know what's wrong. sure, you can remove it after dev/test, but it is priceless during dev. I agree, it can be very useful while developing. Quote Link to comment https://forums.phpfreaks.com/topic/95996-help-listing-users-with-while-loop/#findComment-491452 Share on other sites More sharing options...
discomatt Posted March 13, 2008 Share Posted March 13, 2008 I'd suggest avoiding using double quotes as a general good coding practice. The examples above are better. Quote Link to comment https://forums.phpfreaks.com/topic/95996-help-listing-users-with-while-loop/#findComment-491453 Share on other sites More sharing options...
p2grace Posted March 13, 2008 Share Posted March 13, 2008 Either way would work Quote Link to comment https://forums.phpfreaks.com/topic/95996-help-listing-users-with-while-loop/#findComment-491455 Share on other sites More sharing options...
gtrufitt Posted March 13, 2008 Author Share Posted March 13, 2008 Ok, I changed that to use the concentation . things. i now get the error: Parse error: syntax error, unexpected $end in C:\Inetpub\wwwroot\padgate2\TMPnn10vxohrs.php on line 82 Which the line after the last line of code, why would this be? Quote Link to comment https://forums.phpfreaks.com/topic/95996-help-listing-users-with-while-loop/#findComment-491458 Share on other sites More sharing options...
p2grace Posted March 13, 2008 Share Posted March 13, 2008 This: echo $row['l_name'],"</a><br />\n"; should be echo $row['l_name']."</a><br />\n"; Quote Link to comment https://forums.phpfreaks.com/topic/95996-help-listing-users-with-while-loop/#findComment-491459 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.