每次我刷新页面php将记录添加到databse

时间:2018-11-11 17:11:13

标签: php

    <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>  

我有两个问题。 1-每次刷新我的页面时,代码都会将相同的日期上传到表格中。 我尝试过重定向到标头位置到标头...,但是仍然有相同的问题。 2-当我将此文件(文件upload.php)移动到目录中的另一个文件夹时,下载功能将不起作用。

3 个答案:

答案 0 :(得分:1)

isset函数返回truefalse取决于是否设置了变量。

在您的代码if(isset($_POST['submit'])!="")中检查是否设置了post的提交,返回false,然后尝试与不相等的空字符串进行比较,该字符串返回true ..

if(isset($_POST['submit'])!="")
if(false != "") // isset($_POST['submit']) , when post is not set 
if(true) 

我想你明白了..

您可以通过检查是否为提交集的帖子来做,不需要任何额外的逻辑

if(isset($_POST['submit'))

将完成这项工作。

答案 1 :(得分:0)

好吧,你的情况不对。

更改条件以执行此操作。

发件人: if(isset($_POST['submit'])!=""){

收件人: if(isset($_POST['submit')){

答案 2 :(得分:0)

您应该尝试更改以下行:

if(isset($_POST['submit'])!="")

收件人:

if(isset($_POST['submit']) && $_POST['submit'] != ""){