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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.