Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: How to insert value to textfield in PHP?

  1. #11
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Oops, sorry. Forgot some brackets there.

    Code:
    <?php
    include ('dbconn.cfg');// database configuration file
    $connection = @mysql_connect("localhost", "root", "") or die("Cannot connect to server!");
    ?>
                // build table to display result
                <html>
                <title></title>
                <head>
                <body>
                <h2><center>Member Profile</center></h2>
                <table border = '1'  cellpadding = '3' cellspacing = '2' style = 'background-color: #ADD8E6'>
                <tr>
                <th>Full Name</th>
                <th>Telephone</th>
                <th>Address</th>
                </tr>
                <tr>
                
                <?
    
    if (isset($_SESSION['gmembername']))
    {
        $tbl_name = "member";
        $sql = "SELECT name,telephone,address FROM $tbl_name";
    
        $result = @mysql_query($sql, $connection) or die("Cannot execute query.");
        $numrow = mysql_num_rows($result);
        
        if($numrow != 0)
        {// fetch each record in result set
            for ($counter = 0; $row = mysql_fetch_row($result); $counter++)
          {
                  foreach ($row as $key => $value) {
                    if ($key == 0 && $key == 1) {
    ?>
    <td><input type="text" size="30" value="<?php echo $value;?>" readonly="readonly"></td>
    <?php
             }
               else {
                  if ($row == 2) {
    ?>
    <td><textarea rows="3"> <?php echo $value; ?> </textarea></td>
    <?php
                   }
                }
             }
          }
        }
    }
    ?>
     
                 </tr>
                </table>
                <table>
                <tr>
                <td>&nbsp;</td>
                <td width='4&#37;'>&nbsp;</td>
                <td></tr>
                <tr>
                <td>&nbsp;</td>
                <td width='4%'>&nbsp;</td>
                <td><input type='submit' name='submit' value='Upgrade'></td>
                </table>
                </body>
                </head>
                </html>
    That should work, but not tested.
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  2. #12
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    So weird...the textfield and textarea still missing....

    Quote Originally Posted by thetestingsite View Post
    Oops, sorry. Forgot some brackets there.

    Code:
    <?php
    include ('dbconn.cfg');// database configuration file
    $connection = @mysql_connect("localhost", "root", "") or die("Cannot connect to server!");
    ?>
                // build table to display result
                <html>
                <title></title>
                <head>
                <body>
                <h2><center>Member Profile</center></h2>
                <table border = '1'  cellpadding = '3' cellspacing = '2' style = 'background-color: #ADD8E6'>
                <tr>
                <th>Full Name</th>
                <th>Telephone</th>
                <th>Address</th>
                </tr>
                <tr>
                
                <?
    
    if (isset($_SESSION['gmembername']))
    {
        $tbl_name = "member";
        $sql = "SELECT name,telephone,address FROM $tbl_name";
    
        $result = @mysql_query($sql, $connection) or die("Cannot execute query.");
        $numrow = mysql_num_rows($result);
        
        if($numrow != 0)
        {// fetch each record in result set
            for ($counter = 0; $row = mysql_fetch_row($result); $counter++)
          {
                  foreach ($row as $key => $value) {
                    if ($key == 0 && $key == 1) {
    ?>
    <td><input type="text" size="30" value="<?php echo $value;?>" readonly="readonly"></td>
    <?php
             }
               else {
                  if ($row == 2) {
    ?>
    <td><textarea rows="3"> <?php echo $value; ?> </textarea></td>
    <?php
                   }
                }
             }
          }
        }
    }
    ?>
     
                 </tr>
                </table>
                <table>
                <tr>
                <td>&nbsp;</td>
                <td width='4%'>&nbsp;</td>
                <td></tr>
                <tr>
                <td>&nbsp;</td>
                <td width='4%'>&nbsp;</td>
                <td><input type='submit' name='submit' value='Upgrade'></td>
                </table>
                </body>
                </head>
                </html>
    That should work, but not tested.
    Hope this helps.

  3. #13
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Anyone know that what went wrong in my script?If I only use three textfields then fine,however I can't make any further specifications, so I mix with textarea by specifying it in foreach loop.But all textfields and textarea gone missing... Thanks....

  4. #14
    Join Date
    Feb 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Text fields can't have spaces in them. Text areas can. That's the problem. use string replace or remove them to get the value of a text field to write all then info from the $_REQUEST object.
    Code:
    <input type="text" name="name" size="30" value=<?=(isset($_POST['name']))?str_replace(' ',"&nbsp;",$_POST["name"]):''?>>

Bookmarks

Posting Permissions

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