Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: "Inventory" for HTML RPG  (Read 45084 times)

0 Members and 1 Guest are viewing this topic.

Rob Pomeroy



    Prodigy

  • Systems Architect
  • Thanked: 124
    • Me
  • Experience: Expert
  • OS: Other
Re: "Inventory" for HTML RPG
« Reply #30 on: March 25, 2006, 03:58:23 AM »
Only able to visit the forums sporadically, sorry.

Geek & Dummy - honest news, reviews and howtos

Dilbert

    Topic Starter
  • Moderator


  • Egghead

  • Welcome to ComputerHope!
  • Thanked: 44
    Re: "Inventory" for HTML RPG
    « Reply #31 on: March 25, 2006, 09:50:17 AM »
    You have my thanks. After I get this working, I'll need to know only one more thing before I can get started on the actal stories. And I'm making sure that no part of my game is "too cheesy to launch". I feel like I'm creating my own game engine; my stories'd better match! :D

    Anyhoo, I've set up the appropriate .dll's to get started. I'm looking at the example and I'm taking notes in a notes.txt file, and I'm making sure nothing can be forgotten.

    Let's see... it's called with a $link and I need host, user, and password. According to the STATUS command, my host is localhost, the user is root@localhost, and I know that my password is ********* (not actual password length (I take no chances)).

    Correct me if I'm wrong here or elsewhere. :)

    Code: [Select]
    echo "<table>\n";
    enter the <table> tag and do a line break, right?

    Code: [Select]
    // Printing results in HTML
    echo "<table>\n";
    while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
       echo "\t<tr>\n";
       foreach ($line as $col_value) {
           echo "\t\t<td>$col_value</td>\n";
       }
       echo "\t</tr>\n";
    }
    echo "</table>\n";

    Uh... echo the table, line break, and... variable "line" is whatever the column is? Then echo a table row, then print out every column in a <td>? Then echo the end of the row and go to next row until complete, right? Then end the table? I think I understand it...

    Code: [Select]
    // Free resultset
    mysql_free_result($result);

    Frees memory; I know that.

    Code: [Select]
    mysql_close($link);
    No need to explain that. ;)

    So... let's just see how well this works out...

    [edit]No, it didn't work. Here's my code (with password censored). Can you tell me where I goofed?

    Code: [Select]
    <?php
    $link 
    mysql_connect('localhost''root@localhost''********');
    or die(
    'Could not connect: ' mysql_error());
    echo 
    'Connected successfully';

    mysql_select_db('inventory') or die('Could not select database');

    $query 'SELECT * FROM items';
    $result mysql_query($query) or die('Query failed: ' mysql_error());

    echo 
    "<table>\n";
    while (
    $line mysql_fetch_array($resultMYSQL_ASSOC)) {
     
      echo "\t<tr>\n";
     
      foreach ($line as $col_value) {
           echo 
    "\t\t<td>$col_value</td>\n";
     
      }
     
      echo "\t</tr>\n";
    }
    echo 
    "</table>\n";

    mysql_free_result($result);
    mysql_close($link);
    ?>

    The output of that page is

    Quote
    Parse error: syntax error, unexpected T_LOGICAL_OR in C:\Program Files\Apache Group\Apache2\htdocs\test.php on line 10

    Where line 10 is
    Code: [Select]
    or die('Could not connect: ' . mysql_error());
    It has to do with my login info, doesn't it. I typed my password correctly (i just censored and changed its length in this post) but I wasn't sure about the host. I know what the user is; it told me at the prompt.

    And I still love the prompt for no apparent reason.[/edit]
    « Last Edit: March 25, 2006, 10:00:54 AM by Timothy_Bennett »
    "The geek shall inherit the Earth."

    Rob Pomeroy



      Prodigy

    • Systems Architect
    • Thanked: 124
      • Me
    • Experience: Expert
    • OS: Other
    Re: "Inventory" for HTML RPG
    « Reply #32 on: March 25, 2006, 04:00:10 PM »
    The problem is the semicolon at the end of the line immediately before the "or die..." line.  The "or die" is part of the same command on the previous line.  They can span two lines - that's no problem in PHP, but you must remove the semicolon.

    As a matter of style, I would drop out of the PHP parser when outputting straightforward HTML.  It results in code that runs more efficiently.  So your code would be more like this:

    Code: [Select]
    <?php
    $link 
    mysql_connect('localhost''root@localhost''********')
    or die(
    'Could not connect: ' mysql_error());
    ?>

    <p>Connected successfully</p>
    <?php
    mysql_select_db
    ('inventory') or die('Could not select database');

    $query 'SELECT * FROM items';
    $result mysql_query($query) or die('Query failed: ' mysql_error());
    ?>

    <table>
    <?php
    while ($line mysql_fetch_array($resultMYSQL_ASSOC)) {
    ?>

      <tr>
    <?php
       
    foreach ($line as $col_value) {
    ?>

        <td><?php echo ($col_value != '' $col_value '&nbsp;'); ?></td>
    <?php
       
    }
    ?>

      <tr>
    <?php
    }
    ?>

    </table>
    <?php
    mysql_free_result
    ($result);
    mysql_close($link);
    ?>


    Just to highlight one point - see my change "echo ($col_value != '' ? $col_value : '&nbsp;');"

    This is a conditional statement.  The bit before the question mark is evaluated.  If true, the result given is the bit before the colon; if false, the bit after.  So if $col_value isn't blank, return its value.  If it IS blank, return &nbsp; instead - an HTML non-breaking space.  If you don't do that, certain browsers will render a NULL cell, with no borders, rather than an EMPTY cell with borders.  This is a good practice to adopt when outputting data to a table cell, if you can't be sure that the data will have a printable value.
    « Last Edit: March 25, 2006, 04:10:29 PM by robpomeroy »
    Only able to visit the forums sporadically, sorry.

    Geek & Dummy - honest news, reviews and howtos

    Dilbert

      Topic Starter
    • Moderator


    • Egghead

    • Welcome to ComputerHope!
    • Thanked: 44
      Re: "Inventory" for HTML RPG
      « Reply #33 on: March 26, 2006, 10:12:11 AM »
      I copied the code and pasted it into the file. I put my password back in; my only change to the code. However, I got this error:

      Quote
      Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Group\Apache2\htdocs\test.php on line 9

      Line nine is

      Code: [Select]
      $link = mysql_connect('localhost', 'root@localhost', '********')
      "The geek shall inherit the Earth."

      Rob Pomeroy



        Prodigy

      • Systems Architect
      • Thanked: 124
        • Me
      • Experience: Expert
      • OS: Other
      Re: "Inventory" for HTML RPG
      « Reply #34 on: March 26, 2006, 11:07:28 PM »
      You need to turn on the MySQL module in the php.ini file.  Search in that file for "mysql" and you'll find it.  :)  (You'll need to restart Apache after making this change.)
      Only able to visit the forums sporadically, sorry.

      Geek & Dummy - honest news, reviews and howtos

      Dilbert

        Topic Starter
      • Moderator


      • Egghead

      • Welcome to ComputerHope!
      • Thanked: 44
        Re: "Inventory" for HTML RPG
        « Reply #35 on: March 26, 2006, 11:11:26 PM »
        I found a spot where MySQL had been commented out. I removed the comment and restarted Apache, but I still get the same error.
        "The geek shall inherit the Earth."

        Rob Pomeroy



          Prodigy

        • Systems Architect
        • Thanked: 124
          • Me
        • Experience: Expert
        • OS: Other
        Re: "Inventory" for HTML RPG
        « Reply #36 on: March 27, 2006, 03:58:36 AM »
        Okay, so you've got the line: extension=php_mysql.dll?  You can ignore the extension=php_mysqli.dll (notice the 'i') because you're unlikely to be using that.

        Where was the php.ini file that you edited?  In C:\Windows?  Have you rebooted since you made the change?  (Not that it should be necessary.)
        Only able to visit the forums sporadically, sorry.

        Geek & Dummy - honest news, reviews and howtos

        Dilbert

          Topic Starter
        • Moderator


        • Egghead

        • Welcome to ComputerHope!
        • Thanked: 44
          Re: "Inventory" for HTML RPG
          « Reply #37 on: March 27, 2006, 08:27:19 AM »
          I didn't know there was a C:\WINDOWS\iphp.ini. I'd been editing the one in C:\PHP\ini-recommended. I edited the one in C:\WINDOWS and restarted the server. Still got the same error.

          I'm impressed that you have this degree of patience, personally. I know I'm getting frustrated with me. ;)

          [edit]I made a backup of the php.ini file in C:\WINDOWS, deleted the original, coped the php.ini-reccommended in there and renamed it to php.ini. (I can always go back if I need to)

          And yes, I removed the comment for extension=mysql.dll. No "I" in it, I double-checked it.[/edit]
          « Last Edit: March 27, 2006, 08:36:11 AM by Timothy_Bennett »
          "The geek shall inherit the Earth."

          Rob Pomeroy



            Prodigy

          • Systems Architect
          • Thanked: 124
            • Me
          • Experience: Expert
          • OS: Other
          Re: "Inventory" for HTML RPG
          « Reply #38 on: March 27, 2006, 09:02:09 AM »
          I have just remembered another possible cause of this problem.  Under the PHP installation directory, you will find some "extension" files, which are all DLLs.  Copy them to the C:\Windows\system32 folder, and then restart Apache.  Hopefully that will be the last thing you need to do to fix this.
          Only able to visit the forums sporadically, sorry.

          Geek & Dummy - honest news, reviews and howtos

          Dilbert

            Topic Starter
          • Moderator


          • Egghead

          • Welcome to ComputerHope!
          • Thanked: 44
            Re: "Inventory" for HTML RPG
            « Reply #39 on: March 27, 2006, 09:46:39 AM »
            Did that, and got the same error. *tears hair out*
            "The geek shall inherit the Earth."

            Rob Pomeroy



              Prodigy

            • Systems Architect
            • Thanked: 124
              • Me
            • Experience: Expert
            • OS: Other
            Re: "Inventory" for HTML RPG
            « Reply #40 on: March 27, 2006, 01:57:56 PM »
            Okay, I think we've got to the point where I'd need to get my hands on your system in order to have a good look.  Knowing that your mother will never allow that ;) can you have a look in the event logs to see if they provide any illumination?
            Only able to visit the forums sporadically, sorry.

            Geek & Dummy - honest news, reviews and howtos

            Dilbert

              Topic Starter
            • Moderator


            • Egghead

            • Welcome to ComputerHope!
            • Thanked: 44
              Re: "Inventory" for HTML RPG
              « Reply #41 on: March 27, 2006, 02:20:50 PM »
              OK, if I knew where on the event viewer to find them. I repeated the error in hopes of finding a problem. I found a few suspects. Any of these ring a bell?

              Quote
              Faulting application mmc.exe, version 5.1.2600.2180, faulting module unknown, version 0.0.0.0, fault address 0x00000000.
              For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

              [edit]Actually, I'll PM you the other one. It may contain info I don't want public.[/edit]

              Quote
              Hanging application msimn.exe, version 6.0.2900.2180, hang module hungapp, version 0.0.0.0, hang address 0x00000000.

              For more information, see Help and Support Center at

              Quote
              Windows saved user TIMOTHY\Timothy registry while an application or service was still using the registry during log off. The memory used by the user's registry has not been freed. The registry will be unloaded when it is no longer in use.

               This is often caused by services running as a user account, try configuring the services to run in either the LocalService or NetworkService account.

              For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

              [edit]No idea if it helps, but the [MySQL] section of php.ini:

              [MySQL]
              ; Allow or prevent persistent links.
              mysql.allow_persistent = On

              ; Maximum number of persistent links.  -1 means no limit.
              mysql.max_persistent = -1

              ; Maximum number of links (persistent + non-persistent).  -1 means no limit.
              mysql.max_links = -1

              ; Default port number for mysql_connect().  If unset, mysql_connect() will use
              ; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
              ; compile-time value defined MYSQL_PORT (in that order).  Win32 will only look
              ; at MYSQL_PORT.
              mysql.default_port =

              ; Default socket name for local MySQL connects.  If empty, uses the built-in
              ; MySQL defaults.
              mysql.default_socket =

              ; Default host for mysql_connect() (doesn't apply in safe mode).
              mysql.default_host =

              ; Default user for mysql_connect() (doesn't apply in safe mode).
              mysql.default_user =

              ; Default password for mysql_connect() (doesn't apply in safe mode).
              ; Note that this is generally a *bad* idea to store passwords in this file.
              ; *Any* user with PHP access can run 'echo get_cfg_var("mysql.default_password")
              ; and reveal this password!  And of course, any users with read access to this
              ; file will be able to reveal the password as well.
              mysql.default_password =

              ; Maximum time (in secondes) for connect timeout. -1 means no limit
              mysql.connect_timeout = 60

              ; Trace mode. When trace_mode is active (=On), warnings for table/index scans and
              ; SQL-Errors will be displayed.
              mysql.trace_mode = Off[/edit]
              « Last Edit: March 27, 2006, 03:19:46 PM by Timothy_Bennett »
              "The geek shall inherit the Earth."

              Dilbert

                Topic Starter
              • Moderator


              • Egghead

              • Welcome to ComputerHope!
              • Thanked: 44
                Re: "Inventory" for HTML RPG
                « Reply #42 on: March 28, 2006, 10:53:46 AM »
                Um... he-hello?
                "The geek shall inherit the Earth."

                Rob Pomeroy



                  Prodigy

                • Systems Architect
                • Thanked: 124
                  • Me
                • Experience: Expert
                • OS: Other
                Re: "Inventory" for HTML RPG
                « Reply #43 on: March 29, 2006, 07:14:17 AM »
                Have you definitely got an uncommented line as follows?
                extension=php_mysql.dll

                If not, does this FAQ resolve your problem?

                None of the errors you've posted/PMed are related to this problem, by the way.
                « Last Edit: March 29, 2006, 07:19:28 AM by robpomeroy »
                Only able to visit the forums sporadically, sorry.

                Geek & Dummy - honest news, reviews and howtos

                Dilbert

                  Topic Starter
                • Moderator


                • Egghead

                • Welcome to ComputerHope!
                • Thanked: 44
                  Re: "Inventory" for HTML RPG
                  « Reply #44 on: March 29, 2006, 10:20:53 AM »
                  Quote
                  Have you definitely got an uncommented line as follows?
                  extension=php_mysql.dll

                  Yes:



                  Quote
                  If not, does this FAQ resolve your problem?

                  I'm afraid not. It almost helps, but it's dealing with the actual getting of the database, etc., and I'm having trouble on the login li - that's it! The login details must be incorrect! How can I check on the host and user name?

                  Quote
                  None of the errors you've posted/PMed are related to this problem, by the way.

                   :-/
                  "The geek shall inherit the Earth."