Jump to content

Some Help Here Please..


desjardins2010

Recommended Posts

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>";

}

?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.