hello freinds,

i got a problem with uploadinf files to a server.
What i tried to do was, up load a file to a server and get that file name to a data base. file upoading was done. But data base submision was not done.
A message appears saying, an error in line 50.

i have given my codings too. can anyone help me in finding what the problem is?

codes

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php 

//This is the directory where images will be saved 
$target = "images/"; 
$target = $target . basename( $_FILES['CVFile']['name']); 

//This gets all the other information from the form 
$IP=$_POST['IP']; 
$Username=$_POST['Username']; 
$FullName=$_POST['FullName']; 
$DateofBirth=$_POST['DateofBirth']; 
$Age=$_POST['Age']; 
$Gender=$_POST['Gender']; 
$MaritalStatus=$_POST['MaritalStatus']; 
$LivingAddress=$_POST['LivingAddress']; 
$LivingCountry=$_POST['LivingCountry']; 
$Nationality=$_POST['Nationality']; 
$Religion=$_POST['Religion']; 
$ContactTelephone=$_POST['ContactTelephone']; 
$PrefferedField=$_POST['PrefferedField']; 
$PrefferedFieldOther=$_POST['PrefferedFieldOther']; 
$PrefferedPost=$_POST['PrefferedPost']; 
$PrefferedBusinessField=$_POST['PrefferedBusinessField']; 
$PrefferedBusinessFieldOther=$_POST['PrefferedBusinessFieldOther']; 
$LocalorForeignJob=$_POST['LocalorForeignJob']; 
$JobType=$_POST['JobType']; 
$Qualifications=$_POST['Qualifications']; 
$Experience=$_POST['Experience']; 
$PresentOccupation=$_POST['PresentOccupation']; 
$CV=$_POST['CV']; 
$SendEmails=$_POST['SendEmails']; 
$CVFile=($_FILES['CVFile']['name']); 

// Connects to your Database 
mysql_connect("connection", "Username", "password") or die(mysql_error()) ; 
mysql_select_db("DBName") or die(mysql_error()) ; 

//Writes the information to the database 
mysql_query("INSERT INTO `cv` VALUES (1, '$Username', 1, '$IP', '$Aproval', '$SendEmails', '$FullName', '$DateofBirth', '$Age', '$Gender', '$LivingAddress', '$LivingCountry', '$Nationality', '$Religion', '$MaritalStatus', '$ContactTelephone', '$Mobile', '$email', '$PrefferedField', '$PrefferedFieldOther', '$PrefferedPost', '$PrefferedPostOther', '$PrefferedBusinessField', '$PrefferedBusinessFieldOther', '$LocalorForeignJob', '$JobType', '$Qualifications', '$Experience', 'PresentOccupation', '$CV', '$CVFile', 1);")  

//Writes the photo to the server 
if(move_uploaded_file($_FILES['CVFile']['tmp_name'], $target)) 
{ 

//Tells you if its all ok 
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
} 
else { 

//Gives and error if its not 
echo "Sorry, there was a problem uploading your file."; 
} 
?> 

</body>
</html>

anerror message says
"Parse error: parse error, unexpected T_IF in /home/content/b/a/t/battipanchi/html/another/test/add.php on line 50". so i have given the code for line 50 bellow

//Writes the photo to the server
if(move_uploaded_file($_FILES['CVFile']['tmp_name'], $target))
{

please somebody help me

thanks
sisira

    at the end of that big long mysql_query line - the ; is inside the )
    it should be outside, like this );

      thanks pal. i think it willwork. i will change and test it and will be back.

      thanks
      again
      . hope it will go ok

        hi,

        i did as said. it seems to be right.
        now the files get uploaded to the server. But still the data does not get writen to the data base.

        what might have caused the problem?

        thanks a lot for all thehelp

        sisira

          One problem I notice is that you don't list column fields in your INSERT query, and you have some hard-coded integers in your query. Does the table have an AUTO_INCREMENT id field, perhaps as the first column? If so, you're forcing the id value to be 1 for every query, and since AUTO_INCREMENT columns must be a primary key (and therefore unique), this causes an error when there's already a row in the table with an id of 1. Solution: use the form of INSERT INTO that includes a list of columns to be used in conjunction with the VALUES() list. Also, simply don't include anything for the AUTO_INCREMENT column and any other column for which you don't have any actual data for.

          Second, your query is vulnerable to SQL injection attacks. User-supplied data should never be placed directly into a SQL query. Instead, you must first sanitize it with a function such as [man]mysql_real_escape_string/man.

          Finally, when debugging a SQL problem, it's often helpful to echo out the query that's being sent and to check if the mysql_query() function returned FALSE; if so, output [man]mysql_error/man to get the error message from MySQL.

            helo,

            thanks i will do the said changes. I wil be back with the succefull story.

            untill the above issue to be resolved, now i am uploading files separately, and updating data to the data base separately.

            i have done the following coding for my page uploding. and it works perfectly. so gif files get uploaded perfectly. since i have coded as "images/gif" only gif files get uploaded.

            <?php
            $target = "upload/";
            $target = $target . basename( $_FILES['uploaded']['name']) ;
            $ok=1;

            //This is our size condition
            if ($uploaded_size > 150000)
            {
            echo "Your file is too large.<br>";
            $ok=0;
            }

            //This is our limit file type condition
            if (!($uploaded_type=="image/gif")) {
            echo "You may only upload GIF files.<br>";
            $ok=0;
            }

            //Here we check that $ok was not set to 0 by an error
            if ($ok==0)
            {
            Echo "Sorry your file was not uploaded";
            }

            //If everything is ok we try to upload it
            else
            {
            if(move_uploaded_file($FILES['uploaded']['tmp_name'], $target))
            {
            echo "The file ". basename( $
            FILES['uploadedfile']['name']). " has been uploaded";
            }
            else
            {
            echo "Sorry, there was a problem uploading your file.";
            }
            }
            ?>

            so after that i wanted only MS word files to be uploaded. So i changes the above coding as "text/doc" but after doing that the document file does not get uploaded. what might be the problem.
            The coding works well for a gif file. But doesnt work for the text files.

            Please helpme

            thanks
            sisira

              Did you try echo'ing out the actual type for a M$ Word document to see what it looks like? "text/doc" isn't a valid content type. Also, what if the person uploading a file is smart and refused to pay M$ money for a product that is available free? Better yet, what if they are even smarter and refuse to use a proprietary format (cough M$ /cough) and instead use something like RTF?

              sisira wrote:

              since i have coded as "images/gif" only gif files get uploaded.

              That depends... where is $uploaded_type ever defined? If you're simply taking the value of $_FILES['uploadedfile']['type'], then note that your statement isn't quite true; as per the manual, that value is supplied by the user and no validation is performed to ensure that it's correct (e.g. I could quite easily upload a ".exe" file to your script and simply tell it that it's type is "image/gif").

                Write a Reply...