0

I have a form and I have been developing this website with my localhost and it is working perfect. But when I moved the files to my dedicated server it no longer gets any of the values when I submit the form. I have narrowed it down to two things. A either my server has restricted configurations on the form being submitted but I do not use global variables to get the values so that shouldnt be the problem or the php on the server is older and not allowing me to submit the values the server version i found out is <5.6. Here is my form code:

<form id="company-form" action="scripts/create-library.php" method="post" enctype="multipart/form-data">
<button id="hide-form"><img src="images/minus.png"/></button>
<h3>Add Library Item Form</h3>
<input class="c-name" type="text" name="file-display-name" placeholder="File Display Name"/>
<select class="companies-dd" name="companies">
    <?php
        require_once("../../scripts/connection.php");

        // Select all companies and related data
        $sql = "SELECT company_id, company FROM companies ORDER BY company_id";
        $stmt = $conn->prepare($sql);
        $stmt->execute();
        $stmt->bind_result($c_id, $c);
        while($stmt->fetch()){
            echo "<option value='".$c_id."'>".$c."</option>";
        }
    ?>
</select>
<select class="companies-dd" name="library-cats">
    <?php       
        // Select all companies and related data
        $sql = "SELECT library_category_id, library_category FROM library_categories ORDER BY library_category_id";
        $stmt = $conn->prepare($sql);
        $stmt->execute();
        $stmt->bind_result($l_id, $l);
        while($stmt->fetch()){
            echo "<option value='".$l_id."'>".$l."</option>";
        }
        $conn->close();
    ?>
</select>
<input id="uploadFile" class="image-name" type="text" name="library-file-name" placeholder="No Logo File Chosen" disabled="disabled"/>
<input id="uploadBtn" type="file" name="library-file"/>
<input type="submit" value="Create Item"/>
</form>

This is added the page via ajax call on a button click.

Then the script that I run after the form is submitted is

<?php
session_start();
ini_set('display_errors',1);
error_reporting(-1);

$display = trim($_POST["file-display-name"]);
$company = trim($_POST["companies"]);
$lib_cat = trim($_POST["library-cats"]);

if(empty($display) || empty($company) || empty($lib_cat)){
    $_SESSION["errormsg"] = "Required information is missing please fill out all required fields.";
    header("Location: ../library.php");
}
else{
    $file_name = $_FILES['library-file']['name'];
    $tmp_name = $_FILES['library-file']['tmp_name'];
    $file_size = $_FILES['library-file']['size'];
    $file_type = $_FILES['library-file']['type'];

    $fp = fopen($tmp_name, 'r');
    $content = fread($fp, filesize($tmp_name));
    $content = base64_encode($content);
    fclose($fp);

    if(!get_magic_quotes_gpc()){
        $file_name = addslashes($file_name);    
    }

    if(empty($content)){
        $_SESSION["errormsg"] = "Required information is missing please fill out all required fields (File).";
        header("Location: ../library.php"); 
    }
    else{   
        require_once("connection.php");

        // Insert the logo into the companies photo table
        $sql = "INSERT INTO library_items(filename, mime_type, file_size, file_item, display_name, company_id, library_category_id) VALUES(?,?,?,?,?,?,?)";

        $stmt = $conn->prepare($sql);
        $stmt->bind_param('sssssss', $file_name, $file_type, $file_size, $content, $display, $company, $lib_cat);
        if(!$stmt->execute()){
            $_SESSION["errormsg"] = "Failed to add library item: ".mysqli_error();
            header("Location: ../library.php");
        }
    }
    unset($_SESSION["errormsg"]);

    $_SESSION["successmsg"] = "Library Item successfully added into the database.";
    header("Location: ../library.php");
}

?>

It gives me the errors with the variables saying that they are undefined index's for the form names.

I have read other posts but none of them has helped me. Is there something I am not seeing or I have to change on my server for me to use this?

Alex Beyer
  • 147
  • 1
  • 8
  • Possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – cmorrissey Oct 19 '15 at 19:25
  • where's the tag in your html? – devlin carnate Oct 19 '15 at 19:28
  • Thats not the same type of problem. I know what undefined index means and why it happens. What I do not know is why its working in my local host and the values are correct and do have values that they are not being passed to the script on submit. – Alex Beyer Oct 19 '15 at 19:29
  • sorry that didnt get copied in the is there. – Alex Beyer Oct 19 '15 at 19:30
  • when you submit the form on the server, what does your browser show (in dev tools, like Firebug) as being submitted in POST ? – devlin carnate Oct 19 '15 at 19:31
  • I'm checking on that now give me one sec – Alex Beyer Oct 19 '15 at 19:35
  • The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol. – Alex Beyer Oct 19 '15 at 19:37
  • I don't see a charact encoded that does not belong to the ascii range though. – Alex Beyer Oct 19 '15 at 19:37

1 Answers1

0

Well it looks like the two files I had for testing the upload and display ended up corrupt when I downloaded them. This was causing the server to throw and error saying that the text was outside the US-ASCII range. Since this was not able to be display it didnt transfer any of the forms values. That was the weirdest bug I ever had I guess I will have to start testing my pdfs for errors also.

Alex Beyer
  • 147
  • 1
  • 8