每次我刷新页面时,php都会将记录添加到数据库中 证明 $(文档).ready(函数(){ $('#WellCAT td.exdate')。每个(函数(){ if($(this.text()==cal.getTime();')){ $(this.css('background-color','#ff9933'); } else$(this.css('background-color','#99ccff'); }); }); 证书更新 $(文档).ready(函数(){ $('#WellCAT')。数据表(); });
我有两个问题。。 1-每次刷新我的页面时,代码都会将相同的日期上载到表中。 我已尝试将标题位置重定向到标题。。。但它仍然有同样的问题。。每次我刷新页面时,php都会将记录添加到数据库中 证明 $(文档).ready(函数(){ $('#WellCAT td.exdate')。每个(函数(){ if($(this.text()==cal.getTime();')){ $(this.css('background-color','#ff9933'); } else$(this.css('background-color','#99ccff'); }); }); 证书更新 $(文档).ready(函数(){ $('#WellCAT')。数据表(); });,php,Php,我有两个问题。。 1-每次刷新我的页面时,代码都会将相同的日期上载到表中。 我已尝试将标题位置重定向到标题。。。但它仍然有同样的问题。。 2-当我将此文件(file upload.php)移动到我目录中的另一个文件夹时,下载功能将不起作用。好吧,您的条件是错误的 更改条件以执行此操作 发件人: if(设置($\u POST['submit'])!=“”){ 致: if(isset($\u POST['submit')){isset函数返回true或false取决于变量是否设置 在您的代码中如果(
2-当我将此文件(file upload.php)移动到我目录中的另一个文件夹时,下载功能将不起作用。好吧,您的条件是错误的 更改条件以执行此操作 发件人:
if(设置($\u POST['submit'])!=“”){
致:
if(isset($\u POST['submit')){
isset
函数返回true
或false
取决于变量是否设置
在您的代码中如果(isset($\u POST['submit'])!=“”)正在检查是否设置了提交的帖子,这将返回false,那么您将尝试与不相等的空字符串进行比较,这将返回true
<html>
<title>Certification</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<?php
date_default_timezone_set("Asia/Muscat");
//echo date_default_timezone_get();
?>
<?php
include('connect-db.php');
$Id = $_GET['Id'];
$result = mysql_query("SELECT * FROM master WHERE IDM=$Id")
or die(mysql_error());
$row = mysql_fetch_array($result);
$Asset_Number = $row['Asset_number'];
$Description2 = $row['Description2'];
$Parent_Verified = $row['Parent_Verified'];
$Make=$row['Make'];
$Model=$row['Model'];
$Serial_Number=$row['Serial_Number'];
$Associated_with=$row['Associated_with'];
$Comment=$row['Comment'];
$Date_of_Manufacture=$row['Date_of_Manufacture'];
$Unit=$row['Physically_Verified_Location'];
if(isset($_POST['submit'])!=""){
$name1=$_FILES['photo']['name'];
$size=$_FILES['photo']['size'];
$type=$_FILES['photo']['type'];
$temp=$_FILES['photo']['tmp_name'];
$ext = end((explode(".", $name1)));
$date = date('Y-m-d H:i:s');
$caption1=$_POST['caption'];
$link=$_POST['link'];
$Inspection_type = $_POST['Inspection_type'];
$Inspection_comp = $_POST['Inspection_comp'];
$Inspection_Date = $_POST['Inspection_Date'];
$Expiry_Date = $_POST['Expiry_Date'];
$name = $Asset_Number.'-'.$Inspection_type.'-'.$Inspection_comp.'-'.$Inspection_Date.'-'.$Expiry_Date.'.' . end(explode(".",$_FILES['photo']['name']));
move_uploaded_file($temp,"/files/".$name);
if(mysql_query("INSERT INTO upload (name,date,Asset_Number,Serial_Number,Inspection_type,Inspection_comp,Inspection_Date,Expiry_Date,id_m)VALUES ('$name','$date','$Asset_Number','$Asset_sno','$Inspection_type','$Inspection_comp','$Inspection_Date','$Expiry_Date','$Id')"))
{
header('location:certificate.php');
Exit;
}
else{
die(mysql_error());
}
}
?>
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#WellCAT td.exdate').each(function(){
if ($(this).text() ==cal.getTime();') {
$(this).css('background-color','#ff9933');
}
else $(this).css('background-color','#99ccff');
});
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
<?php include('dbcon.php'); ?>
<div class="col-sm-12 col-md-12 col-lg-12" style="background-color:#33ccff;">
<H4><U><CENTER>CERTIFICATE UPDATE</CENTER></U> </H1>
</div>
</head>
<body>
<div class="container fluid">
<div class="row">
<form class="form-inline" enctype="multipart/form-data" action="" id="wb_Form1" name="form" method="post">
<input type="hidden" name="Id" value="<?php echo $Id; ?>"/>
<div class="col-sm-4" style="background-color:lavender;">
<label class="form-control">ID</label><label class="form-control"><?php echo $Id; ?></label><br>
<label class="form-control">Asset Number</label><label class="form-control"><?php echo $Asset_Number; ?></label><br>
<label class="form-control">Description</label><label class="form-control"><?php echo $Description2; ?></label><br>
<label class="form-control">Parent</label><label class="form-control"><?php echo $Parent_Verified; ?></label><br>
<label class="form-control">Make</label><label class="form-control"><?php echo $Make; ?></label><br>
<label class="form-control">Model</label><label class="form-control"><?php echo $Model; ?></label><br>
<label class="form-control">Serial Number</label><label class="form-control"><?php echo $Serial_Number; ?></label><br></div>
<div class="col-sm-4" style="background-color:lavender;"><br><br>
<label class="form-control">Associated with</label><label class="form-control"><?php echo $Associated_with; ?></label><br>
<label class="form-control">Comment</label><label class="form-control"><?php echo $Comment; ?></label><br>
<label class="form-control">Date of Manufacture</label><label class="form-control"><?php echo $Date_of_Manufacture; ?></label><br>
<label class="form-control">Unit</label><label class="form-control"><?php echo $Unit; ?></label><br></div>
<div class="col-sm-4" style="background-color:lavender;">
<br><br>
<label class="form-control">Inspection type</label><select class="form-control" name="Inspection_type" required="required"> <option value=""></option><br>
<option value="Major">Major Inspection</option>
<option value="Intermediate">Intermediate Inspection</option>
<option value="Other">Other Inspection</option>
</select>
<label class="form-control">Inspection Company</label><input type="text" class="form-control" name="Inspection_comp"><br>
<label class="form-control">Inspection Date</label><input type="date" class="form-control" name="Inspection_Date"><br>
<label class="form-control">Expiry Date</label><input type="date" class="form-control" name="Expiry_Date">
<div class="alert alert-danger" role="alert">
Please choose file here.....(Maximum allowed file size 10Mb)
</div>
<input type="file" class="form-control"name="photo" id="photo" required="required">
<input type="submit" class="btn btn-danger" value="SUBMIT" name="submit">
</div>
</form>
</div>
</div>
<div class="col-md-18">
<div class="container-fluid" style="margin-top:0px;">
<div class = "row">
<div class="panel panel-default">
<div class="panel-body">
<div class="table-responsive">
<form method="post" action="deletefile.php" >
<table id="WellCAT" cellpadding="0" cellspacing="0" border="0" class="table table-condensed" id="example">
<thead>
<tr>
<th>ID</th>
<th>Asset Number</th>
<th>Inspection Type</th>
<th>Inspection Company</th>
<th>Inspection Date</th>
<th>Expiry Date</th>
<th>FILE NAME</th>
<th>Date</th>
<th>Download</th>
<th>Remove</th>
</tr>
</thead>
<tbody>
<?php
$query=mysql_query("select * from upload WHERE id_m=$Id")or die(mysql_error());
while($row=mysql_fetch_array($query)){
$id=$row['id'];
$Asset_Number=$row['Asset_Number'];
$Inspection_type=$row['Inspection_type'];
$Inspection_comp=$row['Inspection_comp'];
$Inspection_Date=$row['Inspection_Date'];
$Expiry_Date=$row['Expiry_Date'];
$name=$row['name'];
$date=$row['date'];
?>
<tr>
<td><?php echo $row['id'] ?></td>
<td><?php echo $row['Asset_Number'] ?></td>
<td><?php echo $row['Inspection_type'] ?></td>
<td><?php echo $row['Inspection_comp'] ?></td>
<td><?php echo $row['Inspection_Date'] ?></td>
<td><?php echo $row['Expiry_Date'] ?></td>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['date'] ?></td>
<td>
<a href="download.php?filename=<?php echo $name;?>" title="click to download"><span class="glyphicon glyphicon-paperclip" style="font-size:20px; color:blue"></span></a>
</td>
<td>
<a href="deletefile.php?del=<?php echo $row['id']?>"><span class="glyphicon glyphicon-trash" style="font-size:20px; color:red"></span></a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
<script>
$(document).ready(function(){
$('#WellCAT').DataTable();
});
</script>
我想你明白了
您可以通过检查提交集是否为post来完成,不需要任何额外的逻辑
if(isset($_POST['submit'])!="")
if(false != "") // isset($_POST['submit']) , when post is not set
if(true)
将完成此工作。您应该尝试更改以下行:
if(isset($_POST['submit'))
致:
更改为if(isset($\u POST['submit')){但仍然相同issue@Siji重新加载时,浏览器是否会显示一个警告框,要求重新提交值?这是否意味着它仍会在数据库中填充记录?@jasvindersingh我也有同感。建议siji打开一个新选项卡进行测试?@jasvindersingh是的,它要求“确认重新提交"您应该对处理与DB的连接的方式做些什么,因为这段代码是一颗滴答作响的定时炸弹,等待着被访问,阅读关于PDO和预安装的语句,以便解决这些巨大的问题issues@Siji您链接到download.php
的方式是该文件移入时停止工作的原因一边是文件夹。阅读相对链接和绝对链接。href=“download.php”
告诉浏览器download.php
与此文件位于同一文件夹中。移动页面后,您需要更新链接,或者将download.php移动到新文件夹中。这同样适用于在download.php
代码中获取要下载的文件的方式
if(isset($_POST['submit'])!="")
if(isset($_POST['submit']) && $_POST['submit'] != ""){