sws Posted November 11, 2006 Share Posted November 11, 2006 Hi all,I have a page that I've created. What I need is to check for user login. If they are logged in then the form displays. If not they get a message stating that the user must be logged in to use this page.I have this part coded and working fine for other static pages.My problem is that the form I'm using contains sql queries using php <? ?> tage. How do I do this ? It's like I have to nest the tags and it's giving me errors.Here's the code I have:[code]<?php include ("config.php"); # Include the config.php file here error_reporting (E_ALL & ~ E_NOTICE); # Don't show notices.if (!empty($online['id'])){ # Check to see if they're logged in echo '<table align="center" border="0" cellpadding="0" cellspacing="0" width="850"> <tr> <td><font face="SerpentineDBol" size="+3" color="#FF0000">Ultimate Poolies.com </font>Welcome <b>'.stripslashes($online['username']).'</b>- <a href="logout.php">Logout</a><br /></td> </tr> <tr> <td height="22" background="images/nav_bar_02.jpg"><font color="#FFFFFF" face="Arial" size="2">Home | Hockey | Football | Basketball | Baseball | Message Boards</font></td> </tr> <tr><td> <table border="1" cellpadding="2" cellspacing="0"> <tr> <td width="232" bgcolor="#EEEEEE>[color=red][b]I need to put code in these td's that contains php tags for queries and such and it's giving me errors.[/b][/color]</td> <td width="530"><br />>[color=red][b]I need to put code in these td's that contains php tags for queries and such and it's giving me errors.[/b][/color]</td> <td width="262" bordercolor="#000000" bgcolor="#EEEEEE"><br />>[color=red][b]I need to put code in these td's that contains php tags for queries and such and it's giving me errors.[/b][/color]</td> </tr> </table> </td> </tr></table>';} else { # Else, they are not logged in. echo 'You must be logged in to use this page.'; /* Note, you could include the login.php file here */ } ?> [/code] Link to comment https://forums.phpfreaks.com/topic/26949-user-authentication-help/ Share on other sites More sharing options...
Orio Posted November 11, 2006 Share Posted November 11, 2006 Where do you set the $online array? Inside config.php?If so, can you show the code of it?Orio. Link to comment https://forums.phpfreaks.com/topic/26949-user-authentication-help/#findComment-123215 Share on other sites More sharing options...
sws Posted November 11, 2006 Author Share Posted November 11, 2006 Yes that's all set in the config.php file. That part of it is working properly because I have other pages working.I have a file called cpanel.php nd it works perfectly:[code]<?php include ("config.php"); # Include the config.php file here error_reporting (E_ALL & ~ E_NOTICE); # Don't show notices.if (!empty($online['id'])){ # Check to see if they're logged in echo '<table align="center" border="0" cellpadding="0" cellspacing="0" width="850"> <tr> <td><font face="SerpentineDBol" size="+3" color="#FF0000">Ultimate Poolies.com </font>Welcome <b>'.stripslashes($online['username']).'</b>- <a href="logout.php">Logout</a><br /></td> </tr> <tr> <td height="22" background="images/nav_bar_02.jpg"><font color="#FFFFFF" face="Arial" size="2">Home | Hockey | Football | Basketball | Baseball | Message Boards</font></td> </tr> <tr><td> <table border="1" cellpadding="2" cellspacing="0"> <tr> <td width="232" bgcolor="#EEEEEE"><br />Welcome to Ultimate Poolies!!</td> <td width="530"><br />This is where the main content will go.</td> <td width="262" bordercolor="#000000" bgcolor="#EEEEEE"><br />Advertizing here !!</td> </tr> </table> </td> </tr></table>';} else { # Else, they are not logged in. echo 'You must be logged in to use this page.'; /* Note, you could include the login.php file here */ } ?> [/code]See in the echo statement there are no php tags in there. I did this to test.Now when I go to add some real code including sql queries and stuff within that echo I am getting errors.I get the following error : Parse error: parse error, unexpected T_STRING in file name on line 43Any advice ?Here's the code: [code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>NHL Pick'em Roster Form</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body bgcolor="#FFFFFF"><?php include ("config.php"); # Include the config.php file here error_reporting (E_ALL & ~ E_NOTICE); # Don't show notices.echo '<table align="center" border="0" cellpadding="0" cellspacing="0" width="850"> <tr> <td height="22" background="images/nav_bar_02.jpg"><font color="#FFFFFF"><marquee behavior="slide" height="22" direction="left">Welcome to ULTIMATE POOLIES.com We are pleased to announce that our HOCKEY Contests are now in progress!!!</marquee></font> </td> </tr> <tr> <td bgcolor="#FFFFFF"><font face="SerpentineDBol" size="+3" color="#FF0000">Ultimate Poolies.com </font>if(!empty($online['id'])){ echo <table align="center" bgcolor="#FFFFFF" border="2" cellpadding="3" cellspacing="3" width="576"> <tr><td align="center" colspan="5"> <h1>Roster Form</h1></td></tr> <form method="post" action="hockey_pickem.php"> <tr><td align="center" colspan="5"> <input type="hidden" name="<? stripslashes($online['username'])?>" value="<? stripslashes($online['username'])?>" /> </td></tr> <tr><td align="center">LW<br /> <select name='players'> <? $lw1_sql = "Select * FROM nhl_players WHERE position = 'LW' ORDER BY name ASC"; $lw1_query = mysql_query($lw1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($lw1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">C<br /> <select name='players'> <? $c1_sql = "Select * FROM nhl_players WHERE position = 'C' ORDER BY name ASC"; $c1_query = mysql_query($c1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($c1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">RW<br /> <select name='players'> <? $rw1_sql = "Select * FROM nhl_players WHERE position = 'RW' ORDER BY name ASC"; $rw1_query = mysql_query($rw1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($rw1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">D<br /> <select name='players'> <? $d1_sql = "Select * FROM nhl_players WHERE position = 'D' ORDER BY name ASC"; $d1_query = mysql_query($d1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($d1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">D<br /> <select name='players'> <? $d2_sql = "Select * FROM nhl_players WHERE position = 'D' ORDER BY name ASC"; $d2_query = mysql_query($d2_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($d2_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> </tr> <tr><td align="center">LW<br /> <select name='players'> <? $lw1_sql = "Select * FROM nhl_players WHERE position = 'LW' ORDER BY name ASC"; $lw1_query = mysql_query($lw1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($lw1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">C<br /> <select name='players'> <? $c1_sql = "Select * FROM nhl_players WHERE position = 'C' ORDER BY name ASC"; $c1_query = mysql_query($c1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($c1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">RW<br /> <select name='players'> <? $rw1_sql = "Select * FROM nhl_players WHERE position = 'RW' ORDER BY name ASC"; $rw1_query = mysql_query($rw1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($rw1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">D<br /> <select name='players'> <? $d1_sql = "Select * FROM nhl_players WHERE position = 'D' ORDER BY name ASC"; $d1_query = mysql_query($d1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($d1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">D<br /> <select name='players'> <? $d2_sql = "Select * FROM nhl_players WHERE position = 'D' ORDER BY name ASC"; $d2_query = mysql_query($d2_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($d2_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> </tr> <tr><td align="center">LW<br /> <select name='players'> <? $lw1_sql = "Select * FROM nhl_players WHERE position = 'LW' ORDER BY name ASC"; $lw1_query = mysql_query($lw1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($lw1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">C<br /> <select name='players'> <? $c1_sql = "Select * FROM nhl_players WHERE position = 'C' ORDER BY name ASC"; $c1_query = mysql_query($c1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($c1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">RW<br /> <select name='players'> <? $rw1_sql = "Select * FROM nhl_players WHERE position = 'RW' ORDER BY name ASC"; $rw1_query = mysql_query($rw1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($rw1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">D<br /> <select name='players'> <? $d1_sql = "Select * FROM nhl_players WHERE position = 'D' ORDER BY name ASC"; $d1_query = mysql_query($d1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($d1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">D<br /> <select name='players'> <? $d2_sql = "Select * FROM nhl_players WHERE position = 'D' ORDER BY name ASC"; $d2_query = mysql_query($d2_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($d2_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> </tr> <tr><td align="center">LW<br /> <select name='players'> <? $lw1_sql = "Select * FROM nhl_players WHERE position = 'LW' ORDER BY name ASC"; $lw1_query = mysql_query($lw1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($lw1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">C<br /> <select name='players'> <? $c1_sql = "Select * FROM nhl_players WHERE position = 'C' ORDER BY name ASC"; $c1_query = mysql_query($c1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($c1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">RW<br /> <select name='players'> <? $rw1_sql = "Select * FROM nhl_players WHERE position = 'RW' ORDER BY name ASC"; $rw1_query = mysql_query($rw1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($rw1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">D<br /> <select name='players'> <? $d1_sql = "Select * FROM nhl_players WHERE position = 'D' ORDER BY name ASC"; $d1_query = mysql_query($d1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($d1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">D<br /> <select name='players'> <? $d2_sql = "Select * FROM nhl_players WHERE position = 'D' ORDER BY name ASC"; $d2_query = mysql_query($d2_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($d2_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> </tr> <tr><td align="center">LW<br /> <select name='players'> <? $lw1_sql = "Select * FROM nhl_players WHERE position = 'LW' ORDER BY name ASC"; $lw1_query = mysql_query($lw1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($lw1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">C<br /> <select name='players'> <? $c1_sql = "Select * FROM nhl_players WHERE position = 'C' ORDER BY name ASC"; $c1_query = mysql_query($c1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($c1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">RW<br /> <select name='players'> <? $rw1_sql = "Select * FROM nhl_players WHERE position = 'RW' ORDER BY name ASC"; $rw1_query = mysql_query($rw1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($rw1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">D<br /> <select name='players'> <? $d1_sql = "Select * FROM nhl_players WHERE position = 'D' ORDER BY name ASC"; $d1_query = mysql_query($d1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($d1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">D<br /> <select name='players'> <? $d2_sql = "Select * FROM nhl_players WHERE position = 'D' ORDER BY name ASC"; $d2_query = mysql_query($d2_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($d2_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> </tr> <tr><td> </td> <td align="center">G<br /> <select name='players'> <? $g1_sql = "Select * FROM nhl_players WHERE position = 'G' ORDER BY name ASC"; $g1_query = mysql_query($g1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($g1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">G<br /> <select name='players'> <? $g1_sql = "Select * FROM nhl_players WHERE position = 'G' ORDER BY name ASC"; $g1_query = mysql_query($g1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($g1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td align="center">G<br /> <select name='players'> <? $g1_sql = "Select * FROM nhl_players WHERE position = 'G' ORDER BY name ASC"; $g1_query = mysql_query($g1_sql) OR DIE ("There was an error" .mysql_error()); while ($table_row = mysql_fetch_array($g1_query,MYSQL_ASSOC)){ $player_id = $table_row['id']; $player = $table_row['name']; echo "<option value='.$player_id.'>$player</option>n"; } ?> </select> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td align="center"><input type="submit" name="submit" value="Submit Picks!" /></td> <td> </td> <td> </td> </tr> </form> </table>';}else { # Else, they are not logged in. echo 'You must be logged in to use this page.'; /* Note, you could include the login.php file here */ } //you dont really need to keep this all in a php tag, can just break out of it, and let rest be all html.. not in an echo or print?> </body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/26949-user-authentication-help/#findComment-123223 Share on other sites More sharing options...
sws Posted November 11, 2006 Author Share Posted November 11, 2006 Am I receiving this error because I've got <?php ... ?> tags nested in <?php ... ?> tags ? Link to comment https://forums.phpfreaks.com/topic/26949-user-authentication-help/#findComment-123263 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.