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.

    <link href="../styles/stylesheet.css" rel="stylesheet" type="text/css">
    <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">
        <td colspan="2">
            <!--the code bellow is used to display the message of the input validation-->
            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>';
        <td width="200"><div align="right" class="arial" >Member ID</div></td>
        <td width="177"><input class="input" name="memID" type="text" /></td>
        <td width="116"><div align="right" class="arial">First Name</div></td>
        <td width="177"><input class="input" name="first" type="text" /></td>
        <td><div align="right" class="arial">Middle Initial</div></td>
        <td><input name="minit" class="input" type="text" /></td>
        <td><div align="right" class="arial">Last Name</div></td>
        <td><input name="last" class="input" type="text" /></td>
        <td width="116"><div align="right" class="arial">Username</div></td>
        <td width="177"><input class="input" name="username" type="text" /></td>
        <td><div align="right" class="arial">Password</div></td>
        <td><input name="password" class="input" type="text" /></td>
        <td><div align="right" class="arial">Group</div></td>
        <td><input name="group" class="input" type="text" /></td>
        <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>

3 Years
Discussion Span
Last Post by gabrielcastillo

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.


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);

        die('Error Connecting to Database: ' . mysql_error());

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

        die('Error selecting Database: ' . mysql_error());

    $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;

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


        echo 'No user foune!';

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.