help needed: how to update php values?

Discussion in 'PHP' started by arale, Jul 14, 2008.

  1. #1
    Hi

    I'm php newbie. For example, I have a php file like this:

    <?
    $value1="content1";
    $value2="content2";
    ?>
    PHP:
    Now I want to create a HTML site with 2 input forms allow me change the values (content1, content2) without edit above file manually. I can enter new data and click update button, then it will update new values of above php file.

    How do I create this file? There are no SQL DB or complicated functions.

    Thank you
     
    arale, Jul 14, 2008 IP
  2. GotSkillz

    GotSkillz Active Member

    Messages:
    101
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #2
    You can do this with the POST function in a form.

    So basically make a form that submits the information to itself.

    
    <form action="<?php echo $PHP_SELF;?>" method="post">
    
    <input name="value1" type="text" />
    
    <input name="value2" type="text" />
    
    <input type="submit" value="submit" name="submit">
    
    
    HTML:
    Then after that, get the form info with php.

    
    //Establish the variables
    
    $value1 = "default_value1";
    $value1 = "default_value2";
    
    //Check to see if form submitted.
    if(isset($_POST['submit'])) {
    
    //Update the Variables
    $value1 = $_POST['value1']
    $value2 = $_POST['value2']
    
    }
    
    
    
    PHP:
    Whatever you want to do with the variables after that is up to you. But that would update the value of the variables based on the information in the form.
     
    GotSkillz, Jul 14, 2008 IP
  3. arale

    arale Guest

    Messages:
    1,215
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks for help but I cant make it works. I got an error with script above.
     
    arale, Jul 14, 2008 IP
  4. GotSkillz

    GotSkillz Active Member

    Messages:
    101
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    What error did you get?
     
    GotSkillz, Jul 15, 2008 IP
  5. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #5
    Guessing it's the missing semi-colons:

    $value1 = $_POST['value1']
    $value2 = $_POST['value2']
     
    Danltn, Jul 15, 2008 IP
  6. arale

    arale Guest

    Messages:
    1,215
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #6
    if I have 2 files: setting.php & config.php

    config.php - file contains values such as $value1="content1"; $value2="content2";
    setting.php - page with 2 input forms and allow user update value from config.php file.

    So ho do I do that? I have tried above code but it didnt change new values.

    Thanks
     
    arale, Jul 16, 2008 IP