Jump to content

pixy

Members
  • Posts

    295
  • Joined

  • Last visited

    Never

Everything posted by pixy

  1. I thought you meant that it was updating the wrong thing. I guess I misunderstood your post. So all of your items have their own iid, and each has their own damage? Which part of your script does that part? It's all a bit jumbled-looking to me. XD
  2. Here's something really quick... (i'm assuming $_SESSION['player'] is the player's user ID [code] <?php // Connect to database session_start(); if (!isset($_SESSION['player'])) {   echo 'You must log in.';   include("footer.php");   die(); } else {   $player = $_SESSION['player']; } if (isset($_GET['equip'])) {   $errors = array();   if (!is_numeric($_GET['equip'])) {     $errors[] = 'You have accessed this page incorrectly.';   }   else {    $equip = trim($_GET['equip']);   }   if (empty($errors)) {     // Make sure they have the item first, and that it's not eqipped     $query = "SELECT status FROM inventory WHERE (iid='$eqip' AND uid='$player')";     $result = mysql_query($query);     if (mysql_num_rows($result) == 1) { // Found item       $row = mysql_fetch_array($result, MYSQL_NUM);       $status = $row[0];       if ($status == 0) { // Not equipped         $query = "UPDATE inventory SET status=1 WHERE (iid='$eqip' AND uid='$player) LIMIT 1";         $result = mysql_query($query);         if ($result) {             echo 'That item has been sucessfully equipped.';         }         else {             echo 'The item could not be equipped due to a mySQL error:<br>'.mysql_error();         }      }      else {        echo 'That item is already equipped.';      }    }    else {     echo 'That item does not belong to you.';    } } else {    echo 'You have accessed this page in error.'; } ?> [/code] I'm not sure if all my { } line up since this little box makes it hard to tell, but thats the jist of it. Then, when you are showing the actual items the person is carying, put a link below to equip.php?equip=1234 or whatever the ID of the item is.
  3. [quote author=fert link=topic=100512.msg396759#msg396759 date=1152841071] use $connection=@mysql_connect("host","user","password"); [/quote] But if you use the @ it suppresses errors, which is not something you want. You need to see the errors to be able to fix them. try this: $connection = mysql_connect("host", "user", "password") or die(mysql_error()); That way it'll tell you WHY the connection failed.
  4. Wouldn't you want to do a while loop for the inventory? In any case, it looks to me like you are making things WAY harder than they have to be. I think instead of making this massive file with all the actions happening, you should consider breaking them up. Then, you can use the $_GET method more effectively for purchasing and equipping the player's items. So you're having no problems buying the items? Just equipping them? Can you have more than one item and leave some of them unequipped? Would you mind if I just wrote an equip.php page for you instead of editing what you have now? It's somewhat ridiculously complicated for what *should* be a simple process.
  5. SELECT column FROM table [b]ORDER BY column[/b] You can also use group by to further organize the data.
  6. www.pixel2life.com has loads of VERY helpful flash tutorials. Thats where I learn everything from. :D
  7. I was going to suggest doing it in flash since it supports PHP scripting in it and such...
  8. ^ I'm already using sessions to store their username. [quote author=akitchin link=topic=100488.msg396635#msg396635 date=1152823294] well if you want to get everyone that has been online in the last 5 minutes, you can use entirely MySQL functions: [code]SELECT username FROM online_users WHERE time_online > DATE_SUB(NOW(), INTERVAL 5 MINUTE)[/code] this will grab the username of anyone whose status was updated in the last 5 minutes (by checking if their hypothetical time_online field is more recent [or greater] than 5 minutes ago). don't forget to change the query to suit however you're storing the users and their time. [/quote] Thanks, that's just what I was looking for!
  9. So how would I query the database to show members online? [code] <?php $time = time() > 5*60; $query = "SELECT username FROM users WHERE (online > '$time')"; $result = mysql_query($query) or mysql_error(); ?> [/code] Can you do that?
  10. Can someone explain detecting session time to me? Would I just create a variable... $_SESSION['time'] = NOW(); and then... How do I add 5 mintes onto NOW() to see if it's been that long?
  11. Couldn't you use that for() loop inside of a while() loop?
  12. See, I really didn't want to have to update the database on every page. Is there [b]any way[/b] to do it without querying the database every time?
  13. I honestly do not understand OOP for my life, so I need to find a way to show users who are logged in without it. How would I go about doing that? It's my own user log in script I made. It has a bunch of fields, but still the basic username, password, email, etc. Are there any tutorials out there for doing this? I googled and didn't find what I was looking for.
  14. Well that just sucks. Thanks for telling me though. I dont want to go through the effort of changing around all my queries. Oh well.
  15. Just clear the cache. For IE Tools>Internet Options>Delete Files
  16. If I want to use mysqli extensions, do I have to change ALL my functions to mysqli? I've got so many regular mysql stuff it would be a royal pain to go in and change all of them. For example, if I connect to the database using mysql_connect, can I use mysqli_query() later in the same script?
  17. Just put it at the top of whatever page you're using. Or, create functions.php and put it in there. Then, just include it in every page you want to use the redirecting function in. include("functions.php"); That way, you don't even have to worry about it. Just use the function to redirect. redirect("page.php", 0);
  18. pixy

    help?

    Just remember to put semi-colons at the end of each line when appropriate because it'll always spit out errors.
  19. $allowed = array('image/gif', 'image/jpeg', 'image/png'); if (in_array($_FILES['upload']['type'], $allowed) {   // Continue to process } else {   // Tell them its bad } And replace ['upload'] with whatever the name of the input you use is.
  20. ^ Agreed, use sessions. They're more secure and easy to use.
  21. pixy

    help?

    <?php include("config.php"); ?> Dont forget the semi-colon, I'm not sure it matters in this case above, but it's a good habbit.
  22. A url redirect? Well, I made myself a function so that I dont have to worry about headers already sending since my website uses sessions and you're supposed to use header("Location: link.php"); or something like that... function redirect($path, $timeout=2, $type=X_REDIRECT_HEADER) {     // Make sure the session isn't split     if (strpos(urldecode($path), "\n") !== false || strpos(urldecode($path), "\r") !== false)     {         error('Tried to redirect to potentially insecure url.');     }     // force session to be written before redirecting     session_write_close();     $type = (headers_sent() || $type == X_REDIRECT_JS ) ? X_REDIRECT_JS : X_REDIRECT_HEADER;     if ($type == X_REDIRECT_JS) {         ?>         <script language="javascript" type="text/javascript">         function redirect() {             window.location.replace("<?php echo $path?>");         }         setTimeout("redirect();", <?php echo ($timeout*1000)?>);         </script>         <?     } else {         if ( $timeout == 0) {             header("Location: $path");         } else {             header("Refresh: $timeout; URL=./$path");         }     }     return true; } Then, when I want to redirect, I just use this: redirect("link.php", 0);
  23. ^ Check the PHP manual. You can download it at php.net and it has examples, how to use it, syntax, and user comments for ways they've used it. Very useful.
  24. http://www.daydreamgraphics.com/d/tutorial/list/45/2 http://www.daydreamgraphics.com/d/tutorial/list/46/2 http://www.daydreamgraphics.com/d/tutorial/list/47/2 Step by step tutorials for making a simple forum. (or, you could always simply install XMB or phpBB or even SMF--they're all free and pretty easy to set up)
  25. ^ That's essentially when I was suggesting. You could make an array of allowed types: $allowed = array('image/gif', 'image/jpeg', 'image/png'); if (in_array($_FILES['upload']['type'], $allowed) {   // Continue to process } else {   // Tell them its bad } And replace ['upload'] with whatever the name of the input you use is.
×
×
  • 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.