desjardins2010 Posted December 16, 2010 Share Posted December 16, 2010 Hey All; I'm going to post two scripts here one is the member.php script the other is a getjob.php as you can see $query = mysql_query("SELECT * FROM npc WHERE LEVEL=1") or die ("Could Not Query Database"); it displays a job I have in a database and selects the number one... what I would like to see is it select jobs that are equal or lessthan the logged in users level I tried using LEVEL=$level as that is a varible set in member.php but I'm gussing this varible donsn't carry over to getjob.php getjob.php <?php //include connect $connect = mysql_connect("localhost","removed","removed") or die ("Could Not Connect To Server"); mysql_select_db('heaven_npc') or die ("Could Not Select Database"); $query = mysql_query("SELECT * FROM npc WHERE LEVEL=1") or die ("Could Not query Database"); echo "<table width='750' border='1'><tr><th><font size='1'>NPC NAME</font></th><th><font size='1'>JOB DESCRIPTION</font></th><th><font size='1'>LEVEL</font></th><th><font size='1'>EXPERIENCE</font></th><th><font size='1'>CASH</font></th><th><font size='1'>REPUTATION</font></th></tr>"; while ($row = mysql_fetch_array($query)) { //set varibles from query $npcname = $row['npcname']; $levels = $row['level']; $jobdes = $row['jobdes']; $exper = $row['exper']; $cash = $row['cash']; $rep = $row['rep']; //end getting varibles echo "<tr align='left'><td>{$row['npcname']}</td><td>{$row['jobdes']}</td><td>{$row['level']}</td><td>{$row['exper']}</td><td>{$row['cash']}</td><td>{$row['rep']}</td></tr>"; } ?> member.php <?php //make connect with server and select database $connect = mysql_connect("localhost","removed","removed") or die ("Could Not Connect To Server"); mysql_select_db('heaven_users') or die ("Could Not Select Database"); //end //query database $sql = mysql_query("SELECT * FROM members WHERE username='$username'"); while ($result = mysql_fetch_assoc($sql)) { $player = $result['username']; $virus = $result['virusscanner']; $cracker = $result['passwordcracker']; $tracer = $result['iptracer']; $account = $result['bankaccountnumber']; $cash = $result['balance']; $exper = $result['exper']; $rep = $result['rep']; $level = $result['level']; } ?> <table align="center" width="186" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="89" height="13"></td> <td width="97"></td> </tr> <tr> <td height="30" colspan="2" valign="top"><div align="center"><?php echo "<font color='#ffffff'>Welcome $player </font>"; ?></div></td> </tr> <tr> <td height="35" valign="top"><div align="left" class="style1">Available Cash</div></td> <td valign="top"><div align="center" class="style9"><?php echo "<font color='#ffffff'>\$$cash.00</font>"; ?></div></td> </tr> <tr> <td height="35" valign="top"><div align="left" class="style1">Experience</div></td> <td valign="top"><div align="center" class="style9"><?php echo "<font color='#ffffff'>$exper</font>"; ?></div></td> </tr> <tr> <td height="35" valign="top"><div align="left" class="style1">Reputation</div></td> <td valign="top"><div align="center" class="style9"><?php echo "<font color='#ffffff'>$rep</font>"; ?></div></td> </tr> <tr> <td height="34" colspan="2" valign="top"><div align="center"><span class="style1">SOFTWARE RUNNING</span></div></td> </tr> <tr> <td height="53" colspan="2" valign="top"><div align="left" class="style9"> <?php echo "<font color='#ffffff'>$virus - $cracker - $tracer</font>"; ?></td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/221815-some-help-here-please/ Share on other sites More sharing options...
desjardins2010 Posted December 16, 2010 Author Share Posted December 16, 2010 for anybody who might be trying to help me out here I can tell you I know that to carry varibles foward you use the session_start(); however as soon as I call this in getjob.php I get an error saying Cannot send session cache limiter - headers already sent... research on google tells me this is associated with WHITE SPACE... dunno script is pretty tight... anyones eyes would help here Quote Link to comment https://forums.phpfreaks.com/topic/221815-some-help-here-please/#findComment-1147911 Share on other sites More sharing options...
Pikachu2000 Posted December 16, 2010 Share Posted December 16, 2010 What do you mean you "tried using LEVEL = $level"? Post the code that's actually giving you the header error, with the session_start() in the place it was in when it gave you the error. Quote Link to comment https://forums.phpfreaks.com/topic/221815-some-help-here-please/#findComment-1147940 Share on other sites More sharing options...
QuickOldCar Posted December 16, 2010 Share Posted December 16, 2010 for anybody who might be trying to help me out here I can tell you I know that to carry varibles foward you use the session_start(); however as soon as I call this in getjob.php I get an error saying Cannot send session cache limiter - headers already sent... research on google tells me this is associated with WHITE SPACE... dunno script is pretty tight... anyones eyes would help here What that usually means is you need to have your session at the top of the page and it's not, something must be coming before your session. Quote Link to comment https://forums.phpfreaks.com/topic/221815-some-help-here-please/#findComment-1147952 Share on other sites More sharing options...
desjardins2010 Posted December 16, 2010 Author Share Posted December 16, 2010 well this is the getcode.php with the session_start(); just under the opening php tag.. on top that php there is html so saying that there is something above it yes html though... session starts just under php tags... <?php session_start(); //include connect $connect = mysql_connect("localhost","heaven","jefF0614") or die ("Could Not Connect To Server"); mysql_select_db('heaven_npc') or die ("Could Not Select Database"); $query = mysql_query("SELECT * FROM npc WHERE LEVEL='$level'") or die ("Could Not query npc Database"); echo "<table width='750' border='1'><tr><th><font size='1'>NPC NAME</font></th><th><font size='1'>JOB DESCRIPTION</font></th><th><font size='1'>LEVEL</font></th><th><font size='1'>EXPERIENCE</font></th><th><font size='1'>CASH</font></th><th><font size='1'>REPUTATION</font></th></tr>"; while ($row = mysql_fetch_array($query)) { //set varibles from query $npcname = $row['npcname']; $levels = $row['level']; $jobdes = $row['jobdes']; $exper = $row['exper']; $cash = $row['cash']; $rep = $row['rep']; //end getting varibles echo "<tr align='left'><td>{$row['npcname']}</td><td>{$row['jobdes']}</td><td>{$row['level']}</td><td>{$row['exper']}</td><td>{$row['cash']}</td><td>{$row['rep']}</td></tr>"; } ? Quote Link to comment https://forums.phpfreaks.com/topic/221815-some-help-here-please/#findComment-1148132 Share on other sites More sharing options...
desjardins2010 Posted December 16, 2010 Author Share Posted December 16, 2010 with that above the error is Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/heaven/public_html/getjob.php:1) in /home/heaven/public_html/getjob.php on line 40 Quote Link to comment https://forums.phpfreaks.com/topic/221815-some-help-here-please/#findComment-1148134 Share on other sites More sharing options...
Pikachu2000 Posted December 16, 2010 Share Posted December 16, 2010 There is a tab or multiple spaces before the opening <?php tag. What you posted doesn't have 40 lines (which is where the error message says the problem is). Quote Link to comment https://forums.phpfreaks.com/topic/221815-some-help-here-please/#findComment-1148137 Share on other sites More sharing options...
desjardins2010 Posted December 16, 2010 Author Share Posted December 16, 2010 Well above that php is html, besides that i thought php don't read white space? can you give me a snipplet of what the structure should be like <?php session_start(); no? Quote Link to comment https://forums.phpfreaks.com/topic/221815-some-help-here-please/#findComment-1148258 Share on other sites More sharing options...
Pikachu2000 Posted December 16, 2010 Share Posted December 16, 2010 You cannot have any output, of any type, to the browser before sending any headers, including session_start(). Quote Link to comment https://forums.phpfreaks.com/topic/221815-some-help-here-please/#findComment-1148266 Share on other sites More sharing options...
desjardins2010 Posted December 16, 2010 Author Share Posted December 16, 2010 would it work if I did <?php session_start(); ?> then the html then the php again? Quote Link to comment https://forums.phpfreaks.com/topic/221815-some-help-here-please/#findComment-1148298 Share on other sites More sharing options...
desjardins2010 Posted December 16, 2010 Author Share Posted December 16, 2010 ok, so that got rid of the error but it still not carrying the varibles with it to the getjob.php file from the member.php file?? i tested output of echo $level; and that return nothing hence no varible being sent? Quote Link to comment https://forums.phpfreaks.com/topic/221815-some-help-here-please/#findComment-1148300 Share on other sites More sharing options...
Pikachu2000 Posted December 16, 2010 Share Posted December 16, 2010 If you're trying to make the value available in a different script, you'd need to assign it to a $_SESSION var, then access it from that var. $_SESSION['level'] = $level; Then in the getjob.php script, $_SESSION['level'] would contain the value that was assigned previously. Quote Link to comment https://forums.phpfreaks.com/topic/221815-some-help-here-please/#findComment-1148301 Share on other sites More sharing options...
desjardins2010 Posted December 16, 2010 Author Share Posted December 16, 2010 k, question when you say in a different script if I open a php and close it then down the page open php again is that another script even though its on the same page? Quote Link to comment https://forums.phpfreaks.com/topic/221815-some-help-here-please/#findComment-1148305 Share on other sites More sharing options...
litebearer Posted December 16, 2010 Share Posted December 16, 2010 you can open and close php as many times as you want in a file; IF you jump/redirect/link to the same another file THEN it is a different file Quote Link to comment https://forums.phpfreaks.com/topic/221815-some-help-here-please/#findComment-1148308 Share on other sites More sharing options...
desjardins2010 Posted December 16, 2010 Author Share Posted December 16, 2010 So I tried as if you look back at member.php a session is open and a varible session storing $_session['username'] is present so I just took that and tried to use it this form $query = mysql_query("SELECT * FROM members WHERE username='$_SESSION['username']'") or die ("Could Not Query Database members"); this game the error $query = mysql_query("SELECT * FROM members WHERE username='$_SESSION['username']'") or die ("Could Not Query Database members"); Quote Link to comment https://forums.phpfreaks.com/topic/221815-some-help-here-please/#findComment-1148310 Share on other sites More sharing options...
desjardins2010 Posted December 16, 2010 Author Share Posted December 16, 2010 opps no this was the error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/heaven/public_html/logfile.php on line 80 Quote Link to comment https://forums.phpfreaks.com/topic/221815-some-help-here-please/#findComment-1148311 Share on other sites More sharing options...
Pikachu2000 Posted December 16, 2010 Share Posted December 16, 2010 logfile.php wasn't even one of the scripts you were asking about . . . Quote Link to comment https://forums.phpfreaks.com/topic/221815-some-help-here-please/#findComment-1148318 Share on other sites More sharing options...
PnzrDrgoon Posted December 16, 2010 Share Posted December 16, 2010 I'm starting to wonder if your my Canadian extended insurance carrier.... If so, this will help me by helping you. 1.) Using SELECT * is sloppy and eats up extra bandwidth gathering columns you don't need. Select only the columns that you are actually using. 2.) WHERE username='$_SESSION['username']'") Try storing $_SESSION['username'] in its own variable and the put that variable into the query. I've tried it your way before and kept getting errors. Try this: $username=$_SESSION['username']; $sql="SELECT `col1`,`col2`,`col3` FROM `members` WHERE `username`='$username' "; $query=mysql_query($sql) OR error_logging_function(); //you do have some sort of error logging function right? So I tried as if you look back at member.php a session is open and a varible session storing $_session['username'] is present so I just took that and tried to use it this form $query = mysql_query("SELECT * FROM members WHERE username='$_SESSION['username']'") or die ("Could Not Query Database members"); this game the error $query = mysql_query("SELECT * FROM members WHERE username='$_SESSION['username']'") or die ("Could Not Query Database members"); Quote Link to comment https://forums.phpfreaks.com/topic/221815-some-help-here-please/#findComment-1148380 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.