2017-04-11 58 views
0

首先,我没有使用任何PHP框架,也没有我目前有一个htaccess文件。我计划在完成后很快添加一个htaccess文件。重定向到一个slu page的页面

我试图让我的网页重定向到按下提交按钮后使用slu page页面的变体。

该网页的网址是:abc.php?user = $ username。该页面有一个编辑按钮,用户可以在其中编辑表格行的内容。我开始尝试只需更新使用的代码如下所示的图像:

else{ 
    $username = $_GET['user']; 

    $users = $db->prepare(" 
     SELECT * FROM users WHERE username = :username LIMIT 1 
    "); 
    $users->bindParam(':username', $_SESSION['user']['username']); 
    $users->execute(['username' => $username]); 
    $users = $users->fetch(PDO::FETCH_ASSOC); 

if(isset($_FILES['files'])) {  // uploads picture to the database 
      foreach($_FILES['files']['name'] as $file => $name) { 
       $filename = $name; 
       try{ 
        if(move_uploaded_file($_FILES['files']['tmp_name'][$file],'uploads/'.$filename)) { 
         $stmt = $db->prepare("UPDATE users SET image = :image WHERE id = :id"); 
         $stmt->bindParam(":image", $filename); 
         $stmt->bindParam(":id", $_SESSION['user']['id']); 
         $stmt->execute(); 
        } 
       } catch(Exception $e) { 
        echo $e; 
       } 
      } 
     } 

我的问题是,当我在编辑页面提交更改,重定向没有任何塞来abc.php。我曾尝试加入

header(“Location:abc.php?user =”。$ username);

问:我怎样才能让它重定向到一个slu page的页面?

回答

0

哦,我发现这只是我表格中的动作(未显示)。

对于任何人遇到此问题,形式应该寻找这样的:

<form action="abc.php?user=<?php echo $username; ?>" method="POST"> 

</form>