0

2 problems, I am getting an undefined index error only for the filename. I have created new pages, but each time the same problem with file names. The data is also not going into the database, its connecting, but nothing being entered.

<?php

include("conn.php");

    $name = $conn->real_escape_string($_POST['FirstName']);
    $surname = $conn->real_escape_string($_POST['Surname']);
    $dateOfBirth = $conn->real_escape_string($_POST['DOB']);
    $emailAddress = $conn->real_escape_string($_POST['email']);
    $phoneNumber = $conn->real_escape_string($_POST['Phone']);
    $address = $conn->real_escape_string($_POST['Address1']);
    $address2 = $conn->real_escape_string($_POST['Address2']);
    $city = $conn->real_escape_string($_POST['City']);
    $county = $conn->real_escape_string($_POST['County']);
    $postcode = $conn->real_escape_string($_POST['Postcode']);
    $password = $conn->real_escape_string($_POST['postpass']);
    $filename = $_FILES['imgupload']['name'];

    $finddate = date("Y-m-d");
    $filetmp = $_FILES['imgupload']['tmp_name'];

move_uploaded_file($filetmp, "../ETimg/".$filename);

$insert = "INSERT INTO ET_UserDetails (FirstName, Surname, DateOfBirth,      EmailAddress, PhoneNumber, Address1, Address2, City, County, Postcode, Pass,   imgpath, Date) VALUES ('$name', '$surname', '$dateOfBirth', '$emailAddress', '$phoneNumber', '$address', '$address2', '$city', '$county', '$postcode', '$password', '$filename', '$finddate')";

The original code where the info is coming from

<div class="form-row">
 <div class="form-group col-lg-6">
     <input type="file" class="form-control" name="imgupload" id ="real-   file" hidden="hidden"/>
      <button type="button" id="custom-button">Select an image file</button>
     <span id="custom-text">No file chosen</span>

       <script type="text/javascript">
 const realFileBtn = document.getElementById("real-file");
 const customBtn = document.getElementById("custom-button");
 const customTxt = document.getElementById("custom-text");

 customBtn.addEventListener("click", function(){
 realFileBtn.click();
 });

 realFileBtn.addEventListener("change", function() {
 if(realFileBtn.value) {
     customTxt.innerHTML = realFileBtn.value.match(/[\/\\]   ([\w\d\s\.\-\(\)]+)$/)[1];
 } else {
     customTxt.innerHTML = "No file chosen yet.";
 }
 });
         </script>
 </div>

David
  • 1
  • 1

1 Answers1

1

i could be wrong here as i'm quite new to PHP myself, but i think you need to wrap it in <form> tags and set the Method="post"

so it would look like:

<form method="post">
    <divs for form and other code here>
</form>

This tells the form data to be POSTED into the $_POST variable.

Sam.92
  • 96
  • 10