Jump to content

Roy766

Members
  • Posts

    28
  • Joined

  • Last visited

    Never

Posts posted by Roy766

  1. No need for edits or deletions. If it becomes absolutely necessary I can manually edit the data, but it shouldn't be for the purpose of the site (only one person will be adding content, and he'll be copying the content from a document previously proofread and edited because he'll be printing it out as well as uploading it). In addition, there's no need to store very much content in the "new" table; any row after the most recent twenty can be automatically cleared. It's simple but efficient and works perfectly for the system I need.

  2. Hello all!

     

    I have a database with six different tables in it ("word", "idea", etc.). Each table has a timestamp column and what I want to do is have a page that lists all the rows entered within a certain time frame (a "New" page). In order to do this, though, I would have to query all six tables and then echo the rows created within a certain time frame. Is this possible?

     

    Thanks in advance!

     

    Also, if anyone has a suggestion on how to return all rows from a certain date onwards, that would be appreciated too.

  3. Hi all!

     

    Sorry if this is in the wrong section, but I'm not really sure if this would relate to PHP, CSS, JS, or just basic HTML.

     

    Just one basic question: I want to have a sort of background image, and then put smaller images on top of it. Think of it sort of like a game: where I have a map and some sprites on top of them.

     

    Sorry for the really stupid question, but I really have no idea how to do this  :-\

  4. Hi, all! I'm not to good with PHP and I was wondering if anyone could help.

     

    I have a simple text box and a submit button. I want a little series of text underneath that text box that echoes every word (separated by a space), on its individual line.

     

    For example, if a user types in "I am awesome" in the box and presses the button, the output would read:

     

    I

    Am

    Awesome

     

    Anybody have any suggestions?

     

    Thanks in advance!

  5. Hi everybody! I'm somewhat new to sessions, so this question may seem really stupid to all of you PHP gods.

     

    Anyways, I'm trying to send a basic PHP variable between two pages through the use of sessions, and then I do some basic computations on the second page. The math I get on the second page is right, but I get these annoying error messages at the top of the page:

     

    First page:

    Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/www/roy766.freehostia.com/armygame.php:6) in /home/www/roy766.freehostia.com/armygame.php on line 8
    
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/www/roy766.freehostia.com/armygame.php:6) in /home/www/roy766.freehostia.com/armygame.php on line 8

     

    Second page:

     

    Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/www/roy766.freehostia.com/armygame2.php:6) in /home/www/roy766.freehostia.com/armygame2.php on line 7
    
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/www/roy766.freehostia.com/armygame2.php:6) in /home/www/roy766.freehostia.com/armygame2.php on line 7

     

    If someone could help it would be greatly appreciated! Thanks in advance!

     

    Side-note:

      session_register();
      session_start();                      
      $_SESSION['budget'] = $budget;

     

     session_start();
    $budget = $_SESSION['budget'];

  6. Well, I decided to try and write a simple script to measure how bad I am at MySQL.

     

    Apparently, very bad.

     

    My idea is simple: You type text into a textbox, it redirects you to a different page, at which the data is sent to the database, and then all of the data is echoed on the main page. Problem is, it doesn't work, and I'm not experienced enough to determine why. All I get when I try to echo is "resource id #2". Here's my code:

     

    Main page (forum.php)

    <html>
    <head>
    <title>Forum thingy....</title>
    </head>
    <body>
    <?php
    mysql_connect("mysql4.freehostia.com", "*******", "******") or die(mysql_error());
    mysql_select_db("aiddre_db") or die(mysql_error());
    
    $result = mysql_query("SELECT * FROM royforum_list");   
    
    while($row = mysql_fetch_assoc($result)){
       echo $result;
    }
    ?>
    <form name="submitcomment" method="post" action="submitcomment.php">
    <input type="text" name="commentval">
    <input type="submit" value="Submit">
    </body>
    </html>

     

    Redirected page (submitcomment.php):

    <?php
        mysql_connect("mysql4.freehostia.com", "aiddre_db", "mioki766") or die(mysql_error());
        mysql_select_db("aiddre_db") or die(mysql_error());
        $commentvalue = $_POST['commentval'];
        $sql = "INSERT INTO royforum_list (comment) VALUES ('$commentvalue')";
        $result = mysql_query($sql);
         echo "Comment posted. Please <a href='forum.php'>return to the forum-ish thing.</a>"
    ?>

     

    Any suggestions?

     

  7. I'm sorry if I have to use some other language. If so, could a mod please move this?

     

    Anyways, I've got a couple of text boxes on my page, and I want it so that there's another text box that automatically updates when one of the other text boxes changes. Any suggestions on how to do this?

  8. Again with this game, I know.

     

    I'm trying to make a text box that automatically updates based on the values of the other text boxes. Problem is, it comes up blank  :'(

     

    Here's what I've got:

     

    <html>
    <head>
    <title>Combat Game</title>
    </head>
    <body>
    
    <script language="VBScript">
    Sub TotalCosts
           TotalCost.Value = 200 - swordfootmen.Value - lancefootmen.Value - mountedswordsmen.Value - mountedlancemen.Value - bowmen.Value - horses.Value - catapaults.Value;
         End Sub
    </script>
    
    You may spend up to 150 gold. For unit prices and stength, consult <a href=unitstuff.php>this graph.</a>
    <form>
    Sword-wielding footmen:<input type="text" name="swordfootmen" onChange="TotalCosts"><br>
    Lance-wielding footmen:<input type="text" name="lancefootmen" onChange="TotalCosts"><br>
    Mounted sword wielders:<input type="text" name="mountedswordsmen" onChange="TotalCosts"><br>
    Mounted lance wielders:<input type="text" name="mountedlancemen" onChange="TotalCosts"><br>
    Bow-wielding footmen:<input type="text" name="bowmen" onChange="TotalCosts"><br>
    Horses:<input type="text" name="horses" onChange="TotalCosts"><br>
    Catapults:<input type="text" name="catapults" onChange="TotalCosts"><br>
    <input type="submit" value="Attack!"><br>
    <br>
    <br>
    Total money left: <input type="text" name="TotalCost" ReadOnly="True">
    
    </form>
    <?php
      $sfcost = $_REQUEST['swordfootmen'] * 3;
      $lfcost = $_REQUEST['lancefootmen'] * 3;
      $mswcost = $_REQUEST['mountedswordsmen'] * 5;
      $mlwcost = $_REQUEST['mountedlancemen'] * 5;
      $bcost = $_REQUEST['bowmen'] * 2;
      $hcost = $_REQUEST['horses'];
      $ccost = $_REQUEST['catapults'] * 12;
      $totalcost = $sfcost + $lfcost + $mswcost + $mlwcost + $hcost + $bcost + $ccost;
      $sfatk = $_REQUEST['swordfootmen'] * rand(1, 5);
      $lfatk = $_REQUEST['lancefootment'] * rand(2, 4);
      $mswatk = $_REQUEST['mountedswordsmen'] * rand(3, 5);
      $mlwatk = $_REQUEST['mountedlancemen'] * rand(3, 4);
      $hatk = $_REQUEST['horses'];
      $batk = $_REQUEST['bowmen'] * rand(1, 4);
      $catk = $_REQUEST['catapults'] * rand(6, 10);
      $totalatk = $sfatk + $lfatk + $mswatk + $mlwatk + $batk + $hatk + $catk;
      $compatk = rand(10, 200);
      if ( $totalcost > 200 )
        {
        echo "You spent too much money! <br />";
        }
      else
        {
        echo "Your total attack force is " . $totalatk . "<br />";
        
       echo 'The computers total attack force is ' . $compatk . "<br />";
      if ( $compatk > $totalatk )
        {
        echo 'Sorry, the computer wins...';
        }
      else
        {
        echo 'You win! Congratulations!';
        }
        }
    ?>
    <br>
    <br>
    </body>
    </html>

  9. Let me give an example with my previously corrected script:

    <?php
      $sfcost = $_REQUEST['swordfootmen'] * 3;
      $lfcost = $_REQUEST['lancefootmen'] * 3;
      $mswcost = $_REQUEST['mountedswordsmen'] * 5;
      $mlwcost = $_REQUEST['mountedlancemen'] * 5;
      $hcost = $_REQUEST['horses'];
      $totalcost = $sfcost + $lfcost + $mswcost + $mlwcost;
      $sfatk = $_REQUEST['swordfootmen'] * 2;
      $lfatk = $_REQUEST['lancefootment'] * 2;
      $mswatk = $_REQUEST['mountedswordsmen'] * 4;
      $mlwatk = $_REQUEST['mountedlancemen'] * 4;
      $hatk = $_REQUEST['horses'];
      $totalatk = $sfatk + $lfatk + $mswatk + $mlwatk + $hatk;
      $compatk = rand(10, 150);
      if ( $totalatk > 150 )
        {
        echo "You spent too much money!";
        }
      else
        {
        echo "Your total attack force is " . $totalatk;
        }
       echo 'The computers total attack force is ' . $compatk;
      if ( $compatk > $totalatk )
        {
        echo 'Sorry, the computer wins...';
        }
      else
        {
        echo 'You win! Congratulations!';
        }
    ?>

    (Don't try just executing that. Requires the HTML to function...)

    When you win, you get:

    Your total attack force is ---The computers total attack force is ---You win! Congratulations!

    Exactly like that. All on one line.

    I'd like it with some line breaks inbetween there.

  10. I'm trying to make a line break in my php echoes...and it's not working...

     

    All my google and yahoo searches are telling me to use

    echo '\n';

     

    ...but that just puts "\n" between the lines...

     

    Help!

  11. Well, I was making a combat game, and I have so far come up with the following code:

     

    <html>
    <head>
    <title>Combat Game</title>
    </head>
    <body>
    <form>
    Sword-wielding footmen:<input type="text" name="swordfootmen"><br>
    Lance-wielding footmen:<input type="text" name="lancefootmen"><br>
    Mounted sword wielders:<input type="text" name="mountedswordsmen"><br>
    Mounted lance wielders:<input type="text" name="mountedlancemen"><br>
    Horses:<input type="text" name="horses"><br>
    <input type="submit" value="Attack!"><br>
    </form>
    <?php
      $sfcost = $_REQUEST['swordfootmen'] * 3;
      $lfcost = $_REQUEST['lancefootmen'] * 3;
      $mswcost = $_REQUEST['mountedswordsmen'] * 5;
      $mlwcost = $_REQUEST['mountedlancemen'] * 5;
      $hcost = $_REQUEST['horses'];
      $totalcost = $sfcost + $lfcost + $mswcost + $mlwcost;
      $sfatk = $_REQUEST['swordfootmen'] * 2;
      $lfatk = $_REQUEST['lancefootment'] * 2;
      $mswatk = $_REQUEST['mountedswordsmen'] * 4;
      $mlwatk = $_REQUEST['mountedlancemen'] * 4;
      $totalatk = $sfatk + $lfatk + $mswatk + $mlwatk + $hcost;
      $compatk = rand(10, 150);
      if ( $totalatk > 150 )
        {
        echo "You spent too much money!";
        }
      else
        {
        echo "Your total attack force is " . $totalatk;
        }
       echo 'The computer's total attack force is ' . $compatk;
      if ( $compatk > $totalatk )
        {
        echo 'Sorry, the computer wins...';
        }
      else
        {
        echo 'You win! Congratulations!';
        }
    ?>
    </body>
    </html>

     

    Well, I've been proofreading the file for the past 20 minutes, and I haven't found a thing.

    I have tried the above code on two different hosts: my freehostia and my T35. Freehostia pops up with:

    Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/www/roy766.freehostia.com/combatgame.php on line 35

    and of course my T35 page just pops up with nothing, as usual.

     

    I have checked line 35 (the second if statement) so many times that I have it memorized, but I can't find a single thing wrong with it.

     

    If somebody finds some stupid mistake I made, I'm gonna slap myself to death  :P.

     

    EDIT: Well, I defined the additional attack power of the horses with their cost...not like it matters. New line:

    $hatk = $_REQUEST['horses'];

    Line twenty-six is now:

    $totalatk = $sfatk + $lfatk + $mswatk + $mlwatk + $hatk;

     

    No difference in the error factor.

     

    EDIT: OH MY GOD! "computer's" ends the echo tag! I AM SO STUPID! Please delete topic!

  12. Ahem.

     

    <html>
    <head>
    <title>Diagonal Line Length Calculator</title>
    </head>
    <body>
    <form>
    X1:<input type="text" name="x1"><br>
    X2:<input type="text" name="x2"><br>
    Y1:<input type="text" name="y1"><br>
    Y2:<input type="text" name="y2"><br>
    <input type="submit" value="Go!"><br>
    </form>
    <br>
    <?php
      $length = pow(sqrt($_REQUEST['x2'] - $_REQUEST['x1']), 2) + pow(sqrt($_REQUEST['72'] - $_REQUEST['y1']), 2)
      echo 'The length of that line is ' . $length
    ?>
    </form>
    </body>
    </html>

×
×
  • 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.