douque8861 2015-06-17 18:51
浏览 32
已采纳

将用户的信息传递到新页面然后进行编辑

I am outputting all of my user's into a table on a page I have called admincustomers.php. I am then attempting to select EDIT on a specific users record. I then route that to a page called editusers.php. I then want all of that specific users information to be outputted on that page. I am not displaying all of the user information I have in my table on admincustomers.php. So when the edit page loads I want to get all of that users information so I have the ability to edit it.

The issue I am having is I am not quite sure how I can carry over the customers ID and get the information to the next page.

admincustomers.php page

$con = mysqli_connect("localhost","root","","bfb");
    $q = mysqli_query($con,"SELECT * FROM users");
?>                  
                            <table class="tableproduct">
                                <tr>
                                    <th class="thproduct">ID</th>
                                    <th class="thproduct">First Name</th>
                                    <th class="thproduct">Last Name</th>
                                    <th class="thproduct">Email</th>
                                    <th class="thproduct">Username</th>
                                    <th class="thproduct">Group</th>
                                    <th class="thproduct"></th>
                                    <th class="thproduct"></th>
                                </tr>   
<?php   
     if(isset($_POST['id']) && is_numeric($_POST['id'])) {
       mysqli_query($con, "DELETE FROM users WHERE id = ". $_POST['id'] ."")
       or die("Could not DELETE: " . mysqli_error($con));
         "Your product was successfully deleted."; 
}   else {Session::flash('adminusers', 'User was successfully deleted.');
}   
        while($row = mysqli_fetch_assoc($q)) : 
?>
                            <form method="POST" action="admincustomers.php">
                                <tr>
                                    <td class="tdproduct"><?php echo $row['id']; ?> </td>
                                    <td class="tdproduct"><?php echo $row['firstname']; ?> </td> 
                                    <td class="tdproduct"><?php echo $row['lastname']; ?> </td>
                                    <td class="tdproduct"><?php echo $row['email']; ?> </td>
                                    <td class="tdproduct"><?php echo $row['username']; ?> </td>
                                    <td class="tdproduct"><?php echo $row['group']; ?> </td>
                                    <td class="tdproduct"><a href='edituser.php?id=<?php echo $row['id']; ?>'>EDIT</a></td>
                                    <input type="hidden" name="id" value="<? echo $row['id']; ?>"/>
                                    <td class="tdproduct"><input name="delete" type="submit" value="DELETE "/></td>
                                </tr>
                            </form> 

<?php   
endwhile;
//Delete message
    if(Session::exists('adminusers')) {
        echo '<p>' . Session::flash('adminusers') . '</p>';
    }
?>
                        </table>    

editusers.php page

I'm trying to escape the users data, but I only get my user information escaped onto the page.

<?php
    $_GET['id'];
?>
                    <form action="" method="post">
                            <div class="field">
                                <label for="firstname">First name</label>
                                <input type="text" name="firstname" class="inputbar" value="<?php echo escape($user->data()->firstname); ?>" required>
                            </div>
                            <div class="field">
                                <label for="lastname">Last name</label>
                                <input type="text" class="inputbar" name="lastname" value="<?php echo escape($user->data()->lastname); ?>" required>
                            </div>
                            <div class="field">
                                <label for="email">Email</label>
                                <input type="email" class="inputbaremail" name="email" value="<?php echo escape($user->data()->email); ?>" required>
                            </div>
                            <div class="field">
                                <label for="username">Username</label>
                                <input type="text" class="inputbar" name="username" value="<?php echo escape($user->data()->username); ?>" required>
                            </div>  

                                <input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
                                <label for="signinButton">
                                    <input type="submit" id="signinButton" value="Update">
                                </label>
                        </form>

What am I doing wrong and how can I go about fixing this issue?

UPDATE:

$user variable

public function __construct($user = null) {
    $this->_db = DB::getInstance();

    $this->_sessionName = Config::get('session/session_name');
    $this->_cookieName = Config::get('remember/cookie_name');

    if(!$user) {
        if(Session::exists($this->_sessionName)) {
            $user = Session::get($this->_sessionName);

            if($this->find($user)) {
                $this->_isLoggedIn = true;
            } else {
                // process Logout
            }
        }
    } else {
        $this->find($user);
    }
}
  • 写回答

1条回答 默认 最新

  • dsubq24666 2015-06-17 19:38
    关注

    In the editusers.php script, look up the user in $_GET['id'] and use that information, not $user.

    <?php
    $con = mysqli_connect("localhost","root","","bfb");
    $stmt = $con->prepare("SELECT firstname, lastname, email, username FROM users WHERE id = ?");
    $stmt->bind_param("i", $_GET['id']);
    $stmt->execute();
    $stmt->bind_result($firstname, $lastname, $email, $username);
    $stmt->store_result();
    if ($stmt->fetch()) { ?>
        <form action="" method="post">
            <div class="field">
                <label for="firstname">First name</label>
                <input type="text" name="firstname" class="inputbar" value="<?php echo htmlentities($firstname); ?>" required>
            </div>
            <div class="field">
                <label for="lastname">Last name</label>
                <input type="text" class="inputbar" name="lastname" value="<?php echo htmlentities($lastname); ?>" required>
            </div>
            <div class="field">
                <label for="email">Email</label>
                <input type="email" class="inputbaremail" name="email" value="<?php echo htmlentities($email); ?>" required>
            </div>
            <div class="field">
                <label for="username">Username</label>
                <input type="text" class="inputbar" name="username" value="<?php echo htmlentities($username); ?>" required>
            </div>  
    
                <input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
                <label for="signinButton">
                    <input type="submit" id="signinButton" value="Update">
                </label>
        </form>
    <?php } else { ?>
        <div>
        User <?php echo htmlentities($_GET['id']); ?> not found.
    <? 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看