Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    593

    Question A little PHP help needed.

    Hi. I have a form that uses php. When ever I load my page it shows a "/" in the input box. How can I change the code so that whenever the page loads it shows a "10" in the input box? This means that the value of $gb must = 10 on the initial load of the webpage. I want the value to remain 10 UNLESS the web user inputs a different amount, then the page reloads and shows the new number in the box and you never see the 10 again unless you exit the browser and start all over.

    I am by no means a php coder, so please help.
    Here is what I have so far.

    Code:
    <form action= <?php echo $_SERVER["PHP_SELF"] ?> method=post>
    
    <!-- input box.   This is where the value should begin at 10 //-->
    <input  name="gb"  type="text" class="style2" size=4 <?
    if (isset($_POST['gb']))
    {
    echo "value={$_POST['gb']}" ;
    }
    else
    {
    echo "value=" ;
    }
    ?> />
    
    <!-- this shows half of the number that was input //-->
    <?
    
    if (isset($gb))
    {
    
    echo (THIS IS HALF OF THE NUMBER INPUT $gb * .5);
    }
    
    ?>
    
    <!-- this is the submit button //-->
    <input type="image" style="font-family: MS Sans Serif; font-size: 9px" src="images/calculate_r6_c2.gif">
    
    </form>
    Check out my new Chrome Extension - Server Admin Tool
    frustratedtech.com - Helpful Server Tech Advice

  2. #2
    Join Date
    Mar 2006
    Posts
    965
    Let's try this:

    PHP Code:
    <form action= <?php echo $_SERVER["PHP_SELF"?> method=post>

    <!-- input box.   This is where the value should begin at 10 //-->
    <input  name="gb"  type="text" class="style2" size=4 <?
    if (isset($_POST['gb']))
    {
    echo 
    "value={$_POST['gb']};
    }
    else
    {
    echo 
    "value=" ;
    }
    ?> />

    <!-- this shows half of the number that was input //-->
    <?

    if (isset($gb))
    {

    echo (
    THIS IS HALF OF THE NUMBER INPUT $gb .5);
    }

    ?>

    <!-- this is the submit button //-->
    <input type="image" style="font-family: MS Sans Serif; font-size: 9px" src="images/calculate_r6_c2.gif">

    </form>
    for :

    PHP Code:
    <?php

    if (isset($_POST['gb'])) {
    $gb = (isset($_POST['gb'])) ? intval(trim($_POST['gb'])) : 10;
    }
    ?>

    <form action="<?php echo $_SERVER["PHP_SELF"?>" method="post">

    <!-- input box.   This is where the value should begin at 10 //-->
    <input  name="gb"  type="text" class="style2" size=4 value="<?php echo $gb?>" />

    <!-- this shows half of the number that was input //-->
    <?

    if (isset($gb))
    {

    echo (
    THIS IS HALF OF THE NUMBER INPUT $gb .5);
    }

    ?>

    <!-- this is the submit button //-->
    <input type="image" style="font-family: MS Sans Serif; font-size: 9px" src="images/calculate_r6_c2.gif">

    </form>
    Is this the type of routine you were looking for ?

  3. #3
    Join Date
    Jan 2004
    Posts
    593
    Doesn't look like it did a single thing.
    I don't see an initial value of 10 in the input box, however the "/" is not in there anymore.
    Check out my new Chrome Extension - Server Admin Tool
    frustratedtech.com - Helpful Server Tech Advice

  4. #4
    Join Date
    Jan 2004
    Posts
    593
    WORKS NOW!

    Looked at your changes and got it to work.
    This is what the top now looks like
    PHP Code:
    <?php

    if (isset($_POST['gb'])) {
    $gb = (isset($_POST['gb'])) ? intval(trim($_POST['gb'])) : 10;
    }
    else 
    $gb 10
    ?>
    Thanks for the help!
    Check out my new Chrome Extension - Server Admin Tool
    frustratedtech.com - Helpful Server Tech Advice

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •