need a help with form $_POST[]

Discussion in 'PHP' started by gurko, Jan 31, 2009.

  1. #1
    I have a profile page where user can edit his data. He can also add own titles. Beside every title is also check box. If checked, the value is yes.

    I don't know how to move the value from each check box to table. The problem is that I can not get the value of $uTitle. To test if the value of it is there, I uncomment the 8th line. I have no idea why it doesn't echo $uTitle.

    Second problem is, even if the value was saved, I would know how to save it into table under column Privacy because under $key aren't just values of uTitle but also of ID.

    [​IMG]
    
    <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
            <table>
                <?php
                echo "
                <tr>
                    <td>Title</td><td>Value</td><td>Privacy</td>
                </tr>";
                //echo $_POST[$uTitle];
                if (isset($_POST))  {
                foreach ($_POST as $key => $value )
                   {
                   mysql_query ("UPDATE titles SET uValue = '$value' WHERE ID ='$key'");
                   }
                   }
                $query =  "SELECT * FROM titles WHERE UserID = $ID";
                $result = mysql_query($query);
                $row = mysql_fetch_assoc($result);
                echo "<br /><b>Edit data:</b>  <br /><br />";
                while($row = mysql_fetch_assoc($result))
                {
                extract ($row);
                echo "
                <tr>
                    <td><b>$uTitle</b></td>
                    <td><input type='text' name='$ID' value='$uValue'></td>
                    <td><input type='checkbox' name='$uTitle' value='yes'>
                </tr>";
                }
                ?>
                <tr><td><input type="submit" value="Update"></td>
                </tr>
            </table>
        </form>
    
    PHP:

     
    gurko, Jan 31, 2009 IP
  2. attila123

    attila123 Active Member

    Messages:
    113
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #2
    Try with echo($_POST["uTitle"]);
     
    attila123, Feb 1, 2009 IP
  3. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #3
    Do not echo empty variables ( $_POST[$uTitle] ) !!
    Try this one .. works for me ;)

    <?php
    $uTitle = $_POST['uTitle'];
    echo $uTitle;
    ?>
    PHP:
     
    ActiveFrost, Feb 1, 2009 IP
  4. jackio

    jackio Banned

    Messages:
    490
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can test the values of POST using:

    print_r($_POST);
    PHP:
    To check if the values are well passed.
     
    jackio, Feb 1, 2009 IP
  5. InovvativeTech

    InovvativeTech Banned

    Messages:
    32
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Usually if the user does not checks the checkbox the value is not posted in to PHP $_POST,hope it helps
     
    InovvativeTech, Feb 2, 2009 IP