0

so im working on an php script that will do a couple of things. First it will take ip,email, and two dates from a user in a form. It will insert these into a table and then using the IP as the key, it will remove the row from table 1(the original table) into table 2(identical to table 1 except with addition of IP,email and two dates. I keep getting undefined comment error, not sure why and also, no SQL action is performed. Any help or guidance will be appreciated!

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

Errors:

Notice: Undefined index: IPAddress
Notice: Undefined index: email
Notice: Undefined index: date_reserved
Notice: Undefined index: date_returned

War10ck
  • 12,387
  • 7
  • 41
  • 54
John Monte
  • 27
  • 6
  • I understand what the error means but not so much why its giving it to me as my syntax appears correct. Its giving it to me for every single variable so i assumed it was something else in my code i cant identify. – John Monte Jul 24 '18 at 20:44
  • I'm no PHP guru, but since PHP is obviously telling you that you are using wrong indices, that implies that the "id" attribute of the DOM element is **NOT** the name of the parameter used in the request. I'm willing to bet the browser is sending the request with parameters set to the "name" attributes. Check them in the developer tools of your browser. If you're using Chrome, hit F12 and navigate to the Network tab. Find your request in there and confirm the parameter names. – Kamil Jarosz Jul 24 '18 at 20:45
  • 2
    @JohnMonte you are not passing the indexes that you are checking in your script. E.g. you check for `IPAddress` but pass `IP Address`, check for `email` but pass `Email` and so on and so forth. They are case sensitive and have to be written exactly the same. How else would PHP know what you mean? – ArSeN Jul 24 '18 at 20:47
  • You were right! I didnt relize php was case sensitive, im a newbie but its a great lesson i will now always keep with me! – John Monte Jul 24 '18 at 20:57

0 Answers0