Jump to content

PHP Form is only sending first character of text field to Database


jusjus7

Recommended Posts

I have a PHP Form where users have to enter and upload a file but when they click upload everything is working except that it is only sending first character of text field to Database!

 

Can any one help??

 

Thanks

 

File upload.php form

<form action="add_file.php" method="post" enctype="multipart/form-data">
           <p><br>
      JobID:
        <input name="JobID" type="text" value="<?php echo $row_Recordset1['JobID']; ?>" readonly="readonly" />
    </p>
    <p>Company ID:
      <input name="CompanyID" type="text" value="<?php echo $row_Recordset1['CompanyID']; ?>" readonly="readonly" />
  </p>
    <p>UserID:
      <input name="UsersID" type="text" /> 
    </p>
    <p>Select File to upload:
      <input type="file" name="uploaded_file" />
  </p>
    <p>Make Sure All Details Are Correct before Submitting!</p>
    <p>
      <input type="submit" value="Submit Application" />
    </p>
        <form>   

add_file.php

// Check if a file has been uploaded
if(isset($_FILES['uploaded_file'])) {
    // Make sure the file was sent without errors
    if($_FILES['uploaded_file']['error'] == 0) {
        // Connect to the database
        $dbLink = new mysqli('localhost', 'user', 'password', 'phpsite');
        if(mysqli_connect_errno()) {
            die("MySQL connection failed: ". mysqli_connect_error());
        }

        // Gather all required data
        $JobID = $dbLink->real_escape_string($_POST['JobID']['JobID']);
      $CompanyID = $dbLink->real_escape_string($_POST['CompanyID']['CompanyID']);
      $UsersID = $dbLink->real_escape_string($_POST['UsersID']['UsersID']);
      $name = $dbLink->real_escape_string($_FILES['uploaded_file']['name']);
        $mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']);
        $data = $dbLink->real_escape_string(file_get_contents($_FILES  ['uploaded_file']['tmp_name']));
       $size = intval($_FILES['uploaded_file']['size']);

        // Create the SQL query
        $query = "
            INSERT INTO `application` (
                `JobID`, `CompanyID`, `UsersID`, `name`, `mime`, `size`, `data`, `N_DateAndTime`
            )
            VALUES (
                '{$JobID}', '{$CompanyID}', '{$UsersID}', '{$name}', '{$mime}', {$size}, '{$data}', NOW()
            )";


        // Execute the query
        $result = $dbLink->query($query);

        // Check if it was successfull
        if($result) {
            echo 'Success! Your job application was successfully sent!';
        }
        else {
            echo 'Error! Failed to insert the file, please try again'
               . "<pre>{$dbLink->error}</pre>";
        }
    }
    else {
        echo 'An error accured while the file was being uploaded, please try again. '
           . 'Error code: '. intval($_FILES['uploaded_file']['error']);
    }

    // Close the mysql connection
    $dbLink->close();
}
else {
    echo 'Error! A file was not sent! Please try again!';
}

// Echo a link back to the main page
echo '<p>Click <a href="year1index.php">here</a> to go back</p>';
?>

 

MOD EDIT:

 . . . 

BBCode tags added.

change $_POST['JobID']['JobID'] to $_POST['JobID'];

same goes for all of the $_POST values.

 

Thank you soo much its worked!! i have been all day trying to figure this out! lol

no problem. please mark as solved

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.