jusjus7 Posted January 23, 2012 Share Posted January 23, 2012 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 https://forums.phpfreaks.com/topic/255612-php-form-is-only-sending-first-character-of-text-field-to-database/ Share on other sites More sharing options...
Pikachu2000 Posted January 23, 2012 Share Posted January 23, 2012 When posting code, enclose it within the forum's . . . BBCode tags. Link to comment https://forums.phpfreaks.com/topic/255612-php-form-is-only-sending-first-character-of-text-field-to-database/#findComment-1310392 Share on other sites More sharing options...
AyKay47 Posted January 23, 2012 Share Posted January 23, 2012 change $_POST['JobID']['JobID'] to $_POST['JobID']; same goes for all of the $_POST values. Link to comment https://forums.phpfreaks.com/topic/255612-php-form-is-only-sending-first-character-of-text-field-to-database/#findComment-1310394 Share on other sites More sharing options...
jusjus7 Posted January 23, 2012 Author Share Posted January 23, 2012 When posting code, enclose it within the forum's . . . BBCode tags. Ok sorry :/ Link to comment https://forums.phpfreaks.com/topic/255612-php-form-is-only-sending-first-character-of-text-field-to-database/#findComment-1310395 Share on other sites More sharing options...
jusjus7 Posted January 23, 2012 Author Share Posted January 23, 2012 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 Link to comment https://forums.phpfreaks.com/topic/255612-php-form-is-only-sending-first-character-of-text-field-to-database/#findComment-1310397 Share on other sites More sharing options...
AyKay47 Posted January 23, 2012 Share Posted January 23, 2012 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 Link to comment https://forums.phpfreaks.com/topic/255612-php-form-is-only-sending-first-character-of-text-field-to-database/#findComment-1310398 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.