I'm working on making a user maintenance system for my class, I have created the add/delete user portion but as for the edit portion I am completely stumped. So far I have created the form but what I want to do is be able to hit find user and then refresh the page with the user chosen to update then change the information and hit save user, since there are many users that can be updated. So far this is what I have for my table.

<html>
<head>
    <link href="../styles/stylesheet.css" rel="stylesheet" type="text/css">
</head>
<body>
    <h1 class="green" align="center"> Enter the information of the user you would like to add</h1>
    <form name="addform" action="edituser_exec.php" method="post">
    <table width="309" border="0" align="center" cellpadding="2" cellspacing="5">
      <tr>
        <td colspan="2">
            <!--the code bellow is used to display the message of the input validation-->
             <?php
            if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) {
            echo '<ul class="err">';
            foreach($_SESSION['ERRMSG_ARR'] as $msg) {
                echo '<li>',$msg,'</li>'; 
                }
            echo '</ul>';
            unset($_SESSION['ERRMSG_ARR']);
            }
        ?>
        </td>
      </tr>
      <tr>
        <td width="200"><div align="right" class="arial" >Member ID</div></td>
        <td width="177"><input class="input" name="memID" type="text" /></td>
      </tr>
      <tr>
        <td width="116"><div align="right" class="arial">First Name</div></td>
        <td width="177"><input class="input" name="first" type="text" /></td>
      </tr>
        <tr>
        <td><div align="right" class="arial">Middle Initial</div></td>
        <td><input name="minit" class="input" type="text" /></td>
      </tr>
      <tr>
        <td><div align="right" class="arial">Last Name</div></td>
        <td><input name="last" class="input" type="text" /></td>
      </tr>
      <tr>
        <td width="116"><div align="right" class="arial">Username</div></td>
        <td width="177"><input class="input" name="username" type="text" /></td>
      </tr>
        <tr>
        <td><div align="right" class="arial">Password</div></td>
        <td><input name="password" class="input" type="text" /></td>
      </tr>
        <tr>
        <td><div align="right" class="arial">Group</div></td>
        <td><input name="group" class="input" type="text" /></td>
      </tr>
      <tr>
        <td><input name="" type="submit" value="Add User" /></td>
        <td><button style="width:100px; position:relative; margin-left:-20%"><a href="../homeAdmin.php" align = "center"> Go back to menu </a></button></td>
        <td><button style="width:130px; position:relative; margin-left:-20%"><a href="../userMaintenance.php">Return to User Page </a></button></td>
      </tr>
    </table>
    </form>

</body>
<html>

Recommended Answers

All 4 Replies

Can u be more specific in what you want the user to do. Moreover, this page is for adding a new user as shown in the submit input. Just a quick information about update page, it's almost the same as the add page in any CMS. However in the update page some input must be deleted or disabled for some unique data that cannot be changed. Finally, in the sql part you have to change the operation from INSERT to UPDATE and add the condition WHERE.

What I'm trying to is give the user the ability to enter some information about a user, then it pulls up the information and allows them to edit it.

Okay and where is the problem: Database ? php code ? or what ?

Here is a simple example of how you would go about setting this up. This code is old style of mysql, you would be better off using PDO.

You can see the database settings are defined at the top, then the mysql connection is made using the settings. After the connection is made, you can see we select the database to use for our queries. Then we check if a post has been made with the user id. This can be made with a dropdown menu and jquery on change function. If post is set with user_id we build our query.. Which selects the row from the table where the user id matches..

If we have 1 record return from the database, we move forward with creating the array for our data in a while loop, else we echo an error. Once the data array is complete we echo out our form, and insert the data from the database into the value of each form input.

Like I said this is a simpel old school way of doing things but will help you to understand the basics of how this is done. Mixing php/jquery/ajax, you can create simple but powerful forms.

//Database Settings:
define('DBHOST'', 'datbase host');
define('DBNAME', 'database name');
define('DBUSER', 'username');
define('DBPASS', 'password');

//Database connection:
$conn = mysql_connect(DBHOST, DBUSER, DBPASS);

    if(!$conn){
        die('Error Connecting to Database: ' . mysql_error());
    }

//Database selection:
$sel = mysql_select_db(DBNAME, $conn );

    if(!$sel){
        die('Error selecting Database: ' . mysql_error());
    }


if(isset($_POST['user_id'])){
    $uid = mysql_real_escape_string($_POST['user_id']);

    $query = mysql_query("SELECT * FROM memebers WHERE user_id='$uid'");

    if(mysql_num_rows($query) == 1){

        $results = array();
        while($row = mysql_fetch_assoc($query))
        {
            $results[] = $row;
        }

        <form>
            <label>Username</label>
            <input type="text" name="" value="<?php echo $results['username']; ?>" />
            <label>Email</label>
            <input type="text" name="" value="<?php echo $results['email']; ?>" />
            <label>Name</label>
            <input type="text" name="" value="<?php echo $results['name']; ?>" />
        </form>


    }else{

        echo 'No user foune!';

    }   
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.