473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Unable to send file using php and mysql please help me

Expand|Select|Wrap|Line Numbers
  1.  <?php
  2. // Check if a file has been uploaded
  3. if(isset($_FILES['uploaded_file'])) {
  4.     // Make sure the file was sent without errors
  5.     if($_FILES['uploaded_file']['error'] == 0) {
  6.         // Connect to the database
  7.         $dbLink = new mysqli('localhost', 'root', '', 'jobsearch');
  8.         if(mysqli_connect_errno()) {
  9.             die("MySQL connection failed: ". mysqli_connect_error());
  10.         }
  11.  
  12.         // Gather all required data
  13.         $name = $dbLink->real_escape_string($_FILES['uploaded_file']['name']);
  14.         $mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']);
  15.         $data = $dbLink->real_escape_string(file_get_contents($_FILES  ['uploaded_file']['tmp_name']));
  16.         $size = intval($_FILES['uploaded_file']['size']);
  17.  
  18.     $fname=$_POST['fname'];
  19.     $lname=$_POST['lname']; 
  20.     $emailid=$_POST['emailid'];
  21.     $country=$_POST['country'];
  22.     $city=$_POST['city'];
  23.     $bdate=$_POST['bdate'];
  24.     $bmonth=$_POST['bmonth'];
  25.     $byear=$_POST['byear'];
  26.     $gender=$_POST['gender'];
  27.     $contact=$_POST['contact'];
  28.     $degree=$_POST['degree'];
  29.     $major=$_POST['major'];
  30.     $gpa=$_POST['gpa'];
  31.     $cmonth=$_POST['cmonth'];
  32.     $cyear=$_POST['cyear'];
  33.     $jobtype=$_POST['jobtype'];
  34.     $exp=$_POST['exp'];
  35.     $indus=$_POST['indus'];
  36.     $jobfunction=$_POST['jobfunction'];
  37.     $keyskill=$_POST['keyskill'];
  38.     $resumetile=$_POST['resumetile'];   
  39.  
  40.  
  41.  
  42.         //This is the directory where images will be saved 
  43.  $target = "resumes/"; 
  44.  $target = $target . basename($_FILES['uploaded_file']['name']); 
  45.  
  46.         // Create the SQL query
  47.         $query = "
  48.             INSERT INTO ` jobseeker` (
  49.                `name`, `mime`, `size`, `data`, `fname`, `lname, `emailid`, `country`, `city`, `bdate`, `bmonth`, `byear`, `gender`, `contact`, `degree`, `major`, `gpa`, `cmonth`, `cyear`, `jobtype`, `exp`, `indus`,  `jobfunction`,  `keyskill`, `resumetile`,`created`
  50.             )
  51.             VALUES (
  52.             '{$name}', '{$mime}', '{$size}', '{$data}', '{$fname}', '{$lname}', '{$emailid}', '{$country}', '{$city}', '{$bdate}', '{$bmonth}', '{$byear}', '{$gender}', '{$contact}', '{$degree}', '{$major}', '{$gpa}', '{$cmonth}', '{$cyear}', '{$jobtype}', '{$exp}', '{$indus}',  '{$jobfunction}',  '{$keyskill}', '{$resumetile}',  NOW()
  53.             )";
  54.  
  55.  
  56.  
  57.         // Execute the query
  58.         $result = $dbLink->query($query);
  59.  
  60.  
  61.         //Writes the photo to the server 
  62.  if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $target)) 
  63.  { 
  64.  
  65.  //Tells you if its all ok 
  66.  //echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
  67.  } 
  68.  else { 
  69.  
  70.  //Gives and error if its not 
  71.  echo "Sorry, there was a problem uploading your file."; 
  72.  } 
  73.  
  74.  
  75.  
  76.         // Check if it was successfull
  77.         if($result) {
  78.             echo 'Success! Your file was successfully added!';
  79.         }
  80.         else {
  81.             echo 'Error! Failed to insert the file'
  82.                . "<pre>{$dbLink->error}</pre>";
  83.         }
  84.     }
  85.     else {
  86.         echo 'An error accured while the file was being uploaded. '
  87.            . 'Error code: '. intval($_FILES['uploaded_file']['error']);
  88.     }
  89.  
  90.     // Close the mysql connection
  91.     $dbLink->close();
  92. }
  93. else {
  94.     echo 'Error! A file was not sent!';
  95. }
  96.  
  97. // Echo a link back to the main page
  98. echo '<p>Click <a href="newfile.html">here</a> to go back</p>';
  99. ?>
  100.  
  101.  (
Dec 9 '13 #1
0 1414

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: ADE | last post by:
Hi everyone well from my last post I found what I am looking for I have some code now that transfers files I have added a GUI to it and need some help with two things one my loadtemplate()...
1
by: Sridhar Reddy | last post by:
Hi, Where can i get the download mysql.sock file? I am unable to connect to local server because i dont have this file? thanx in advance Sridhar
0
by: Jacek Francuz | last post by:
Hi! How can I change button image end send file to Client in one request? I try to change image in first step and I add onstartupscript: "Form1.submit()" and then in second step I send...
3
by: SM | last post by:
Hello, Im trying to access elements in my XML file using the JavaScript DOM but i'm not sure how. I use AJAX to access the XML and then use the responseXML property to access the XML file data. I...
12
Rahulnewdelhi
by: Rahulnewdelhi | last post by:
hello all Hello all I installed php, mysql and IIS in xp. Problem is this while i run following file PHP Code: ---------------- <?php
0
by: ic3s | last post by:
I need help in completing my program that sends files using java. What I wanted, instead of putting the text in a string then send, I want to save it to file in my local drive and the program would...
8
by: malaysiauser | last post by:
Im new user of PHP and MySQL. I tried to use a script package for my web. I'd created a database. And my connection scripts are as follow; <?php $mysql_host="localhost"; ...
1
by: vyasanjali | last post by:
Hi I am trying to my site user to a other site api using SOAP client . But Every time its give uncatchable error. I am using nusoap class .But shows error that given below: Fatal error:...
1
by: phanimadhav | last post by:
hello friends i need your help.Any one please help me. Actually my client requirement is store the .doc file into MYSQL .So please help me if u have any code or any url please send me.Thank you
4
by: Francesca | last post by:
Hi everybody, I am a real newbie in both perl and relational databases like mysql, and I have been banging my head on the wall trying to understand how to populate a mysql database using an Excel...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.