弹出窗口打开一个 PHP 页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15704704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:47:00  来源:igfitidea点击:

Popup window to open up a PHP page

phpjavascriptjquery

提问by elmmm

I have a manage users page which lets users to delete and update users. I'd like to make the delete and update users pages to be pop up windows with a close window option. but I don't know how, here is my mange users code

我有一个管理用户页面,允许用户删除和更新用户。我想让删除和更新用户页面成为带有关闭窗口选项的弹出窗口。但我不知道如何,这是我的管理用户代码

<?php
//MY PHP stuff
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8” />
<title>Manage Users</title>
<link rel="stylesheet" type="text/css" href="../allcss/style.css" />
</head>

<body>

<?php
require('../Login/includes/header.inc.php');
?>

<div id="personalised">
<p>Hello, </p>
</div>
<div id="content">
<table>
  <tr>
    <th scope="col">User email</th>
    <th scope="col">User name</th>
    <th scope="col">User role</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
  </tr>
  <?php while($row = $result ->fetch_assoc()) { ?>
  <tr>
    <td><?php echo $row['user_email']; ?></td>
    <td><?php echo $row['user_name']; ?></td>
    <td><?php echo $row['user_role']; ?></td>
    <td><a href="update_users.php?person_id=<?php echo $row['person_id']; ?>">EDIT</a></td>
    <td><a href="delete_users.php?person_id=<?php echo $row['person_id']; ?>">DELETE</a></td>
  </tr>
  <?php } ?>
</table>
</div>


</body>
</html>

And this is the update_user.php page

这是 update_user.php 页面

<?php

require_once 'login.php'; 
$table="users";
$OK = false;
$done = false;
$conn = new mysqli ($host, $user, $password, $database) or die("Connection Failed");

$stmt= $conn->stmt_init();

if (isset($_GET['person_id']) && !$_POST) {
  // prepare SQL query
  $sql = 'SELECT person_id, user_email, user_name, user_role FROM users
          WHERE person_id = ?';
  if ($stmt->prepare($sql))
  {
  $stmt->bind_param('i', $_GET['person_id']);
  $stmt->bind_result($person_id, $user_email, $user_name, $user_role);
  $OK = $stmt->execute();
  $stmt->fetch();
  $_SESSION['uemail_update'] = $user_email; //new
  }
}
if (isset($_POST ['update'])) {
  // prepare update query
  $sql = 'UPDATE users SET user_name = ?, user_role = ?
          WHERE person_id = ?';
  if ($stmt->prepare($sql)) {
    $stmt->bind_param('ssi', $_POST['user_name'], $_POST['user_role'], $_POST['person_id']);
    $done = $stmt->execute();
  }
}
// redirect if $_GET['aperson_id'] not defined
if ($done) {
  header('Location: update_users_confirm.php');
  exit;
}
if (!isset($_GET['person_id'])) {
  header("Location: manage_users.php");
  exit;
}
// store error message if query fails
if (isset($stmt) && !$OK && !$done) {
  $error = $stmt->error;
}
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8” />
<title>Project Confirmation</title>
<link rel="stylesheet" type="text/css" href="../allcss/style.css" />
</head>

<body>

<?php
require('../Login/includes/header.inc.php');
?>

<div id="personalised">
<p>Hello, </p>
</div>
<div id="content">
<?php 
if (isset($error)) {
  echo "<p class='warning'>Error: $error</p>";
}
if($person_id == 0) { ?>
  <p class="warning">Invalid request: user does not exist.</p>
<?php } else { ?>
<form id="form1" method="post" action="">
  <p>
    <label for="user_name">User name:</label>
    <input name="user_name" type="text" class="widebox" id="user_name" value="<?php echo htmlentities($user_name, ENT_COMPAT, 'utf-8'); ?>">
  </p>
  <p>
    User role: <select name="user_role" size="1" id="user_role">
    <option value="PT">Part timer</option>
    <option value="FT">Full timer</option>
    <?php echo htmlentities($user_role, ENT_COMPAT, 'utf-8'); ?></select>
  </p>
  <p>
    <input type="submit" name="update" value="Update Entry" id="update">
    <input name="person_id" type="hidden" value="<?php echo $person_id; ?>">
  </p>
</form>
<?php } ?>
</div>



</body>
</html>

Can someone please help me to make the update_user.php page appear in a pop up window which should also display confirmation.php page when its submitted.

有人可以帮助我使 update_user.php 页面出现在一个弹出窗口中,该窗口在提交时也应该显示confirmation.php 页面。

Thanks

谢谢

回答by Toretto

You can do it by JavaScriptsee the solution given below:

您可以通过JavaScript查看下面给出的解决方案来做到这一点:

Add this script on top of the page in head section

在 head 部分的页面顶部添加此脚本

<script>
function pop_up(url){
window.open(url,'win2','status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=1076,height=768,directories=no,location=no') 
}
</script>

Replace these line on your code

替换代码中的这些行

<td>
    <a href="update_users.php?person_id=<?php echo $row['person_id']; ?>" onclick="pop_up(this);">EDIT</a>
</td>
<td>
    <a href="delete_users.php?person_id=<?php echo $row['person_id']; ?>" onclick="pop_up(this);">DELETE</a>
</td>

Hope it will help.

希望它会有所帮助。

回答by biren4www

Use java scripts function.

使用java脚本功能。

function popupCenter(pageURL, title, w, h) {
    var left = (screen.width / 2)  - (w / 2);
    var top  = (screen.height / 2) - (h / 2);
    var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}

<a href="#" onclick="popupCenter('delete_users.php?person_id=<?php echo $row['person_id']; ?>')">DELETE</a>