我正在建立一个库存管理系统,如果您登录,您将被重定向到客户信息。
这是我在登录页面中的代码:
<?php
if(isset($_SESSION['KEY']))
{
header("location:datagrid_customer_info.php");
}
else
{
if(isset($_POST['btnLogin'])){
require_once("_config.php");
$txtEmail = $_POST['txtEmail'];
$txtPassword = $_POST['txtPassword'];
$STH = $DBH->prepare("SELECT * FROM view_login_info WHERE cEmail =:txtEmail AND cPassword =:txtPassword");
$STH->bindparam(":txtEmail",$txtEmail);
$STH->bindparam(":txtPassword",$txtPassword);
$STH->execute();
$ROW = $STH->fetch(PDO::FETCH_ASSOC);
$CTR = $STH->rowCount();
if($CTR==1){
session_start();
$_SESSION['idLogin'] = $ROW['idLogin'];
$_SESSION['KEY'] = 1;
$STH = $DBH->prepare("UPDATE adm_login_info SET cLock=0, cLastLogin = DATE_FORMAT(NOW(),'%Y-%m-%d %H:%i:%s') WHERE idLogin=:idLogin");
$STH->bindparam(":idLogin",$ROW['idLogin']);
$STH->execute();
echo "<script type='text/javascript'>";
echo "alert('Welcome to Inventory Management System');";
echo "window.location.href='datagrid_customer_info.php';";
echo "</script>";
}else{
echo "<script type='text/javascript'>";
echo "alert('Login Error!');";
echo "window.location.href='login.php';";
echo "</script>";
}
}
?>
<html>
<head>
<title>Inventory Management System Ver. 1</title>
<link href="css/main.css" rel="stylesheet" type="text/css">
</head>
<body>
<div style="width:22%;margin:60px auto;">
<form action="<?=htmlentities($_SERVER['PHP_SELF'])?>" method="post">
<div id="panel_head"><img src="images/nav_icons/inv.png" align="left"> SYSTEM LOGIN</div>
<div id="panel_body">
<table cellpadding="2" cellspacing="2" width="100%" class="table_style">
<tbody>
<tr>
<td>EMAIL</td>
<td><input type="text" required name="txtEmail" size="25" autocomplete="off"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="text" required name="txtPassword" size="25" autocomplete="off"></td>
</tr>
</tbody>
</table>
</div>
<div id="panel_footer">
<input type="submit" value="Login" name="btnLogin">
<input type="reset" value="Cancel">
</div>
</form>
</div>
</body>
</html>
<?php
}
?>
我的索引代码:
<?php
session_start();
if(!isset($_SESSION['KEY'])==0)
{
header('location:datagrid_customer_info.php');
}
else
{
header("location:index.php");
}
?>
我的客户信息页码:
<?php
require_once("_config.php");
if(isset($_REQUEST['del_id']))
{
$STH=$DBH->prepare("DELETE FROM inv_customer_info WHERE idCustomer=:id");
$STH->bindparam(":id",$_REQUEST['id']);
$STH->execute();
header("Location:datagrid_customer_info.php");
}
?>
<html>
<head>
<title>Customer Information</title>
<link href="css/main.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
function selectRow(row)
{
var firstInput = row.getElementsByTagName('input')[0];
firstInput.checked = !firstInput.checked;
}
function checkAll(ele) {
var checkboxes = document.getElementsByTagName('input');
if (ele.checked) {
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].type == 'checkbox') {
checkboxes[i].checked = true;
}
}
} else {
for (var i = 0; i < checkboxes.length; i++) {
console.log(i)
if (checkboxes[i].type == 'checkbox') {
checkboxes[i].checked = false;
}
}
}
}
</script>
<script type="text/javascript">
function fnDelete(clicked_id) {
var r = confirm("Are you sure you want to delete this item?");
if (r == true) {
window.location.href='datagrid_customer_info.php?del_id=';
} else {
window.location.href='index.php';
}
}
function fnEdit(clicked_id){
window.location.href='edit_customer_info.php?id='+clicked_id;
}
function fnInsert(){
window.location.href='new_customer_info.php';
}
</script>
</head>
<body style="position:absolute; top:0px; margin:0px;">
<?php
include("top_navigation.php");
?>
<form action="" method="post">
<div style="width:75%;margin:60px auto;">
<div id="panel_head"><img src="images/customer.png"
align="left"> CUSTOMER INFORMATION</div>
<div id="panel_body">
<table border="0" cellpadding="1" cellspacing="1" width="98%"
id="myTable" class="table_style">
<thead>
<tr>
<th><input type="checkbox" onchange="checkAll(this)"
name="chk[]"></th>
<th> </th>
<th colspan="2">Customer</th>
<th>DOB</th>
<th>Age</th>
<th>Gender</th>
<th>Billing Address</th>
<th> </th>
<th colspan="2"> </th>
</tr>
<thead>
<tbody>
<?php
//$start=0;
//$limit=3;
//$id=$_GET['id'];
//$start=($id-1)* $limit;
$STH = $DBH->prepare("SELECT * FROM view_customer_info ORDER BY
TransactDate DESC");
$STH->execute();
$CTR = $STH->rowCount();
while($ROW = $STH->fetch(PDO::FETCH_ASSOC)) {
if($ROW['fGender']=='Male'){
$img_gender = "images/male.png";
}else{
$img_gender ="images/female.png";
}
if($ROW['New']==1){
$new = "images/new.png";
}else{
$new = "images/old.png";
}
if($ROW['fStatus']=='Active'){
$img_status = "images/active.png";
}else{
$img_status = "images/inactive.png";
}
?>
<tr class="row_style" onclick="selectRow">
<td align="center"><input type="checkbox" name="" value="<?
=$ROW['idCustomer']?>"></td>
<td align="center"><img src="<?=$new?>"></td>
<td align="center"><?=$ROW['id']?></td>
<td><img src="<?=$img_gender?>"> <?=$ROW['fCustomerName']?>
</td>
<td><?=$ROW['DOB']?></td>
<td><?=$ROW['Age']?></td>
<td><?=$ROW['Gender']?></td>
<td><?=$ROW['cBillingAddress']?></td>
<td><img src="<?=$img_status?>"></td>
<td align="center" width="3%">
<input type="button" onclick="fnEdit(this.id)" value="Edit"
id="<?=$ROW['idCustomer']?>">
</td>
<td align="center" width="3%">
<input type="button" onclick="fnDelete(this.id)"
value="Delete" id="<?=$ROW['idCustomer']?>">
</td>
</tr>
<?php
}
?>
<tr>
<td> </td>
<td colspan="8"> </td>
<td colspan="2"> </td>
</tr>
</tbody>
</table>
</div>
<div id="panel_footer">
<input type="button" onclick="fnInsert(this.id)" value="Insert New">
<input type="submit" name="cmdDelete" value="Delete Selected">
<?php
require_once("_config.php");
if(isset($_REQUEST['cmdDelete'])){
if(isset($_REQUEST['cmdCheck'])){
$checkbox = $_REQUEST['cmdCheck'];
for($i=0;$i<count($checkbox);$i++){
$del_id = $checkbox[$i];
$STH = $DBH->prepare("DELETE FROM inv_customer_info
WHERE idCustomer=:del_id");
$STH->bindparam(":del_id",$del_id);
$STH->execute();
echo "<script type='text/javascript'>";
echo "alert('Successfully Deleted');";
echo
"window.location.href='datagrid_customer_info.php';";
echo "</script>";
}
}
}else{
$checkbox = "";
}
?>
</div>
</div>
</form>
</body>
</html>
我真的不知道这里有什么问题。我已经检查了我的饼干。
答案 0 :(得分:0)
问题似乎是由无限重定向循环引起的。我建议它在这里:
for($i=0;$i<count($checkbox);$i++){
$del_id = $checkbox[$i];
$STH = $DBH->prepare("DELETE FROM inv_customer_info WHERE idCustomer=:del_id");
$STH->bindparam(":del_id",$del_id);
$STH->execute();
echo "<script type='text/javascript'>";
echo "alert('Successfully Deleted');";
echo "window.location.href='datagrid_customer_info.php';";
echo "</script>";
}
您正在循环重定向。
另外,在php中使用标题可能很复杂,我建议您使用刷新元标记。您可以在PHP中使用它:
<?php
$location = 'destination/file.php?variable=value';
echo '<META http-equiv="refresh" content="0;URL='.$location.'">';
?>