Results 1 to 2 of 2

Thread: MySQL to a Form and Back Again

  1. #1
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default MySQL to a Form and Back Again

    Okay, so I figured out the login script that I was working on-- except for a few small problems which I can't fix until this one is solved. . . So, here it is!

    I need to first display all of the usernames as hyperlinks. When one is clicked, I need to pull their info out of the MySQL database and display it in a from (i.e. the username in a text box) so that the info can be edited and then "saved," if you will. How do I do this? The obvious part is

    print '<form>';
    print "<input type='text' value='$username'>"; etc.
    print '<form>';

    But could someone give me an example of how I might do the rest? (I don't need the entire code-- at least I hope not )

    Thanks!
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
      if(!is_numeric($id = (@$_GET['id'] or $_POST['id'])))
        // throw an error and die
    
      $users_table = 'users';
      $acceptable_rows = array('username', 'email');
      if(isset($_POST['username'])) {
        foreach($acceptable_rows as $row => $value)
          mysql_query(sprintf('update &#37;s where id=%d set \'%s\'=\'%s\'', $users_table, $id, $row, $value));
        // output a success message and die
      }
    
      $user = mysql_fetch_array(mysql_query(sprintf('select * from %s where id=%d', $users_table, $id)));
    ?>
    <form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post">
      <table>
        <thead>
          <tr>
            <th>ID</th>
            <th>Username</th>
            <th>Email Address</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>
              <?php echo($user['id']); ?>
              <input type="hidden" name="id" value="<?php echo($user['id']); ?>">
            </td>
            <td>
              <input type="text" name="username" value="<?php echo($user['username']); ?>">
            </td>
            <td>
              <input type="text" name="email" value="<?php echo($user['email']); ?>">
            </td>
            <td>
              <input type="submit" value="OK">
            </td>
          </tr>
        </tbody>
      </table>
    </form>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •