thedigicraft / Atom.CMS

Atom.CMS
56 stars 52 forks source link

Part 57: Users displaying in menu but not in form #169

Closed dbashby closed 8 years ago

dbashby commented 8 years ago

I have my users displaying in the left column but the form fields will not populate. I have gone through the video 3 times checking my code and cannot see where my error is. I would be grateful if someone could point me in the right direction. Thanks

screenshot1

The user section of my switch:

`case "users":

        if(isset($_POST['submitted']) == 1){

            $first = mysqli_real_escape_string($dbc, $_POST['firstname']);
            $last = mysqli_real_escape_string($dbc, $_POST['lastname']);

            if(isset($_POST['id']) != ''){
                $action = 'updated!';
                $q = "UPDATE users SET firstname = '$first', lastname = '$last', password = '$_POST[password]', status = $_POST[status] WHERE id = $_GET[id]";

            } else {
                $action = 'added!';
                $q = "INSERT INTO users (firstname, lastname, password, status) VALUES ('$first', $last, '$_POST[password]', '$_POST[status]')";

            }

            $r = mysqli_query($dbc, $q);

            #Debug Query:
            if($r){
                $message = '<p>User was ' . $action . '</p>';
            } else {
                $message = '<p>User could not be ' . $action . ' because: ' . mysqli_error($dbc);
                $message .= '<p>' . $q . '</p>';
            }

        }

        if(isset($_GET['id'])){ $opened = data_user($dbc, $_GET['id']); }

    break;`

User.php code minus the rows and columns at either end of the code.

`

New User

            </a>
        <?php 

            $q = "SELECT * FROM users ORDER BY firstname ASC";
            $r = mysqli_query($dbc, $q);

            while($list = mysqli_fetch_assoc($r)){ 

                $list = data_user($dbc, $list['id']);
                //$blurb = substr(strip_tags($page_list['body']), 0, 141);

            ?>

                <a class="list-group-item <?php selected($list['id'], $opened['id'], 'active'); ?>" href="index.php?page=users&id=<?php echo $list['id']; ?>">
                    <h4 class="list-group-item-heading"><?php echo $list['fullname']; ?></h4>
                    <!--<p class="list-group-item-text"><?php // echo $blurb; ?></p>-->
                </a>

        <?php } ?>

        </div><!-- end of list-group -->

    </div><!-- End col-md-4 -->

<div class="col-md-7"><!-- column for form -->

<?php if(isset($message)){ echo $message; } ?>

    <form action="index.php?page=users&id<?php echo $opened['id']; ?>" method="post" role="form">

        <div class="form-group">
            <label for="first">First Name:</label>
            <input class="form-control" type="text" name="first" id="first" value="<?php echo $opened['firstname']; ?>" placeholder="First Name">
        </div>

         <div class="form-group">
            <label for="last">Last Name:</label>
            <input class="form-control" type="text" name="last" id="last" value="<?php echo $opened['lastname']; ?>" placeholder="Last Name">
        </div>

         <div class="form-group">
            <label for="status">Status:</label>
            <select class="form-control" name="status" id="status">

                <option value="0" <?php if(isset($_GET['id'])){ selected('0', $opened['status'], 'selected'); } ?>>Inactive</option>
                <option value="1" <?php if(isset($_GET['id'])){ selected('1', $opened['status'], 'selected'); } ?>>Active</option>

            </select>
        </div>

        <div class="form-group">
            <label for="password">Password:</label>
            <input class="form-control" type="password" name="password" id="password" value="" placeholder="Password">
        </div>

        <button type="submit" class="btn btn-success">Save</button>
        <input type="hidden" name="submitted" value="1">
        <input type="hidden" name="id" value="<?php echo $opened['id']; ?>">

    </form>

<?php 

       // echo mysqli_error($dbc); // See if mysql has any error to report.
       // echo '<br>'.$q; // Output the query just to see if there is an obvious mistake.

     ?>`
dbashby commented 8 years ago

As an added bonus prior to working on this section I had the page manager working with the active class indicating which page was selected but now that no longer works.

creptor commented 8 years ago

Ah god, you have a lot of problems :3

Same as before, just read this at 4 am, so i'll look it up tomorrow... good night

dbashby commented 8 years ago

I rectified the issue by going back to the start, as you noted I was having a lot of issues and could not spot the issues. Thanks for all your help so far. I have got to video 53, so far so good. Has that tempted fate!