插入,删除行并将其移动到另一个表的HTML表单---

时间:2018-07-24 20:39:41

标签: php html sql

所以我正在研究一个PHP脚本,它将做几件事。首先,它将以表格形式从用户处获取ip,email和两个日期。它将插入到表中,然后使用IP作为键,它将表1(原始表)中的行移到表2(与表1相同)中,除了增加IP,电子邮件和两个日期。出现未定义的注释错误,不确定原因,并且也不会执行任何SQL操作。任何帮助或指导将不胜感激!

   <?php

   $connect = mysqli_connect("reserve1", 
   "root", "","server_31");
   $status = "";
   if(isset($_POST['new']) && 
   $_POST['new']==1){
   $IPAddress = $_REQUEST['IPAddress'];
   $email = $_REQUEST['email'];
   $Date_reserved = 
   $_REQUEST['date_reserved'];
   $Date_returned = 
   $_REQUEST['date_returned'];

   $sql="INSERT INTO 'servers_in_use'
   (`IPAddress`,'Email'`Date_Reserved`, 
    `Date_Returned`,) VALUES
   ('$IPAddress','$email','$Date_reserved',  
    '$Date_returned',)";
  $sql="INSERT INTO 'servers_in_use'    
   SELECT * FROM 'servers' WHERE IPAddress= 
  $IPAddress";
  $sql="DELETE FROM servers   WHERE 
  IPAddress =$IPAddress";

   mysqli_query($connect, $sql);
 }
 ?>
 <!DOCTYPE html>
 <html>
 <head>
 <meta charset="utf-8">
 <title>Make a Reservation</title>
 <link rel="stylesheet" 
 href="css/style.css" 
 />
 </head>
 <body>
 <div class="form" align="center">
 <p><a href="dashboard.php">Main Menu</a> 
 | <a href="view.php">View Available 
 Servers</a> 
 | <a href="view.php">View Reserved 
 Servers</a>

 <div align ="center">
 <h1>Make A Reservation</h1>
 <form name="form" method="post" action=""> 
 <input type="hidden" name="new" value="1" 
 />
 <p><input type="text" name="IP Addrress" 
 placeholder="Enter Server IP" required /> 
 </p>
 <p><input type="email" name="Email" 
 placeholder="Enter Email" required /></p>
 <p><input type="date" name="Date Reserved" 
 placeholder="Enter Date" required /></p>
 <p><input type="date" name="Date Returned" 
 placeholder="Enter Date" required /></p>
 <p><input name="submit" type="submit" 
 value="Submit" /></p>
 </form>
 <p style="color:#FF0000;"><?php echo 
 $status; ?></p>
 </div>
 </div>
 </body>
 </html>

错误:

  

通知:未定义的索引:IPAddress
  注意:未定义索引:电子邮件
  注意:未定义的索引:date_reserved
  注意:未定义索引:date_returned

1 个答案:

答案 0 :(得分:-1)

未定义索引表示数组索引不存在。 $_REQUEST的所有4个变量读取都在发生这种情况。您可以先检查它们是否存在:

if (isset($_REQUEST['IPAddress'])) { ...

您还应该仅在发布这些变量的情况下才插入数据库。